diff --git a/src/mock-doc/document.ts b/src/mock-doc/document.ts index d9f59a63f2f..16d8b9eb481 100644 --- a/src/mock-doc/document.ts +++ b/src/mock-doc/document.ts @@ -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; diff --git a/src/mock-doc/test/element.spec.ts b/src/mock-doc/test/element.spec.ts index fd972370bf5..768466566d1 100644 --- a/src/mock-doc/test/element.spec.ts +++ b/src/mock-doc/test/element.spec.ts @@ -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 = '0';