From 0435acb5ae6fbcb3cbd283382997e926fdbaeb80 Mon Sep 17 00:00:00 2001 From: Sean O'Grady <1761115+seanogdev@users.noreply.github.com> Date: Sun, 19 Nov 2023 13:48:27 +0000 Subject: [PATCH] #1163@patch: Selection anchorOffset should return a number. --- packages/happy-dom/src/selection/Selection.ts | 2 +- packages/happy-dom/test/selection/Selection.test.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/happy-dom/src/selection/Selection.ts b/packages/happy-dom/src/selection/Selection.ts index 68952f52f..a0b9045c0 100644 --- a/packages/happy-dom/src/selection/Selection.ts +++ b/packages/happy-dom/src/selection/Selection.ts @@ -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 diff --git a/packages/happy-dom/test/selection/Selection.test.ts b/packages/happy-dom/test/selection/Selection.test.ts index e1be6e563..f0c32299b 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}".`, () => {