Skip to content

Commit

Permalink
feat(mock-doc): add pathname to mock anchors (#3090)
Browse files Browse the repository at this point in the history
add pathname to mock anchors - the pathname is generated
based on the href and returned
  • Loading branch information
tricki committed Oct 11, 2021
1 parent 47cb4bb commit 99428c7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/mock-doc/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ export class MockAnchorElement extends MockHTMLElement {
set href(value: string) {
this.setAttribute('href', value);
}
get pathname() {
return new URL(this.href).pathname;
}
}

export class MockButtonElement extends MockHTMLElement {
Expand Down
14 changes: 14 additions & 0 deletions src/mock-doc/test/element.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -432,4 +432,18 @@ describe('element', () => {
expect(input.list).toEqual(null);
});
});

describe('link', () => {
it('href', () => {
const elm: MockAnchorElement = doc.createElement('a');
elm.href = 'http://stenciljs.com/path/to/page';
expect(elm.href).toBe('http://stenciljs.com/path/to/page');
});

it('pathname', () => {
const elm: MockAnchorElement = doc.createElement('a');
elm.href = 'http://stenciljs.com/path/to/page';
expect(elm.pathname).toBe('/path/to/page');
});
});
});

0 comments on commit 99428c7

Please sign in to comment.