diff --git a/packages/happy-dom/src/selection/Selection.ts b/packages/happy-dom/src/selection/Selection.ts index b142cbdd6..3504d0bfe 100644 --- a/packages/happy-dom/src/selection/Selection.ts +++ b/packages/happy-dom/src/selection/Selection.ts @@ -92,7 +92,7 @@ export default class Selection { */ public get anchorOffset(): number { if (!this.#range) { - return null; + return 0; } return this.#direction === SelectionDirectionEnum.forwards ? this.#range.startOffset diff --git a/packages/happy-dom/test/selection/Selection.test.ts b/packages/happy-dom/test/selection/Selection.test.ts index cd722bbf1..5cec5d2fb 100644 --- a/packages/happy-dom/test/selection/Selection.test.ts +++ b/packages/happy-dom/test/selection/Selection.test.ts @@ -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}".`, () => {