Skip to content

Commit

Permalink
capricorn86#1163@patch: Selection anchorOffset should return a number.
Browse files Browse the repository at this point in the history
  • Loading branch information
seanogdev committed Nov 19, 2023
1 parent 9a0062b commit 0435acb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/happy-dom/src/selection/Selection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default class Selection {
*/
public get anchorOffset(): number {
if (!this._range) {
return null;
return 0;
}
return this._direction === SelectionDirectionEnum.forwards
? this._range.startOffset
Expand Down
4 changes: 2 additions & 2 deletions packages/happy-dom/test/selection/Selection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ describe('Selection', () => {

for (const property of ['anchorOffset', 'baseOffset', 'focusOffset', 'extentOffset']) {
describe(`get ${property}()`, () => {
it('Returns null if no Range has been added.', () => {
expect(selection[property]).toBe(null);
it('Returns 0 if no Range has been added.', () => {
expect(selection[property]).toBe(0);
});

it(`Returns start offset of Range if direction is "${SelectionDirectionEnum.forwards}".`, () => {
Expand Down

0 comments on commit 0435acb

Please sign in to comment.