Skip to content

Commit

Permalink
fix(mock-doc): set document.dir property from document.documentElement
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Mar 22, 2021
1 parent f463cb2 commit 9a65494
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/mock-doc/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ export class MockDocument extends MockHTMLElement {
}
}

get dir() {
return this.documentElement.dir;
}
set dir(value: string) {
this.documentElement.dir = value;
}

get location() {
if (this.defaultView != null) {
return (this.defaultView as Window).location;
Expand Down
16 changes: 16 additions & 0 deletions src/mock-doc/test/element.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ describe('element', () => {
doc = new MockDocument();
});

it('document.documentElement dir', () => {
expect(doc.dir).toBe('');
expect(doc.documentElement.getAttribute('dir')).toBe(null);
doc.documentElement.setAttribute('dir', 'rtl');
expect(doc.documentElement.getAttribute('dir')).toBe('rtl');
expect(doc.dir).toBe('rtl');
});

it('document.dir', () => {
expect(doc.dir).toBe('');
doc.dir = 'ltr';
expect(doc.dir).toBe('ltr');
doc.dir = 'rtl';
expect(doc.dir).toBe('rtl');
});

it('insertAdjacentElement beforebegin', () => {
const elm = doc.createElement('div') as MockHTMLElement;
elm.innerHTML = '<b>0</b>';
Expand Down

0 comments on commit 9a65494

Please sign in to comment.