Skip to content

Commit

Permalink
fix(mock-doc): add html collections to document
Browse files Browse the repository at this point in the history
fixes #1925
  • Loading branch information
manucorporat committed Oct 4, 2019
1 parent 2e327f7 commit 0bf3877
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/mock-doc/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,26 @@ export class MockDocument extends MockHTMLElement {
return this.location.href;
}

get styleSheets() {
return this.querySelectorAll('style');
}

get scripts() {
return this.querySelectorAll('script');
}

get forms() {
return this.querySelectorAll('form');
}

get images() {
return this.querySelectorAll('img');
}

get scrollingElement() {
return this.documentElement;
}

get documentElement() {
for (let i = this.childNodes.length - 1; i >= 0; i--) {
if (this.childNodes[i].nodeName === 'HTML') {
Expand Down
32 changes: 32 additions & 0 deletions src/mock-doc/test/element.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,38 @@ describe('element', () => {
expect(elm).toEqualHtml(`<meta content="updated" id="test">`);
});

it('document.styleSheets', () => {
expect(document.styleSheets).toEqual([]);
const style = document.createElement('style');
document.head.appendChild(style);
expect(document.styleSheets).toEqual([style]);
});

it('document.forms', () => {
expect(document.forms).toEqual([]);
const form = document.createElement('form');
document.head.appendChild(form);
expect(document.forms).toEqual([form]);
});

it('document.scripts', () => {
expect(document.scripts).toEqual([]);
const script = document.createElement('script');
document.head.appendChild(script);
expect(document.scripts).toEqual([script]);
});

it('document.images', () => {
expect(document.images).toEqual([]);
const img = document.createElement('img');
document.head.appendChild(img);
expect(document.images).toEqual([img]);
});

it('document.scrollingElement', () => {
expect(document.scrollingElement).toBe(document.documentElement);
});

it('document.title', () => {
document.title = 'Hello Title';
expect(document.title).toBe('Hello Title');
Expand Down

0 comments on commit 0bf3877

Please sign in to comment.