Skip to content

Commit

Permalink
test(watcher): test skipping middlewares on hyperlinks with appropria…
Browse files Browse the repository at this point in the history
…te selectors
  • Loading branch information
sneko committed Jun 3, 2022
1 parent 65cfadf commit b7e4d95
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/watcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ describe('HyperlinkWatcher', () => {
<div>
<a id="main-link" href="https://example.com">Hey</a>
<a class="specific" href="https://specific.com"></a>
<a id="skipped-link" data-skip-middlewares href="https://skipped.com"></a>
<a class="custom-do-not-use-middlewares" href="https://skipped.com"></a>
</div>
`;

Expand Down Expand Up @@ -116,4 +118,37 @@ describe('HyperlinkWatcher', () => {
'_self'
);
});

it('should skip hyperlinks tagged with the default data attribute "to skip"', () => {
hyperlinkWatcher = new HyperlinkWatcher({
composition: mdwComposition,
});

hyperlinkWatcher.watch();
window.open = jest.fn();

const skippedHyperlink = document.querySelector(
'#skipped-link'
) as HTMLAnchorElement;

skippedHyperlink.click();
expect(window.open).not.toHaveBeenCalled();
});

it('should skip hyperlinks tagged with the custom selector "to skip"', () => {
hyperlinkWatcher = new HyperlinkWatcher({
selector: 'a:not(.custom-do-not-use-middlewares)',
composition: mdwComposition,
});

hyperlinkWatcher.watch();
window.open = jest.fn();

const skippedHyperlink = document.querySelector(
'.custom-do-not-use-middlewares'
) as HTMLAnchorElement;

skippedHyperlink.click();
expect(window.open).not.toHaveBeenCalled();
});
});

0 comments on commit b7e4d95

Please sign in to comment.