Skip to content

Commit

Permalink
Merge pull request #1164 from seanogdev/fix-selection-spec
Browse files Browse the repository at this point in the history
#1163@patch: Selection anchorOffset should return a number.
  • Loading branch information
capricorn86 committed Jan 15, 2024
2 parents ee4eb6f + 08ad2c7 commit 5faca75
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 @@ -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
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 5faca75

Please sign in to comment.