Skip to content

Commit

Permalink
test: add test specs.
Browse files Browse the repository at this point in the history
  • Loading branch information
andycall committed Nov 23, 2024
1 parent 25002f2 commit 9d41a9a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
3 changes: 2 additions & 1 deletion bridge/core/html/html_anchor_element.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Element} from "../dom/element";
import {HTMLElement} from "./html_element";

interface HTMLAnchorElement extends Element {
interface HTMLAnchorElement extends HTMLElement {
target: DartImpl<string>;
accessKey: DartImpl<string>;
download: DartImpl<string>;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions integration_tests/specs/dom/events/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -786,4 +786,42 @@ describe('Event', () => {
el.style.width = '102px';
el2.style.width = '102px';
});

it('should works with preventDefault in `<a /> element', async (done) => {
const anchorElement = createElement('a', {}, [createText('')]);
BODY.append(anchorElement);

anchorElement.addEventListener('click', async (e) => {
e.preventDefault();

BODY.append(createText('Nothing happened'));

await snapshot();
done();
});

anchorElement.click();
});

it('should satisfy react-router event check', (done) => {
function isModifiedEvent(event: MouseEvent) {
return !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey);
}
function shouldProcessLinkClick(event: MouseEvent) {
return event.button === 0 &&
// Let browser handle "target=_blank" etc.
!isModifiedEvent(event) // Ignore clicks with modifier keys
;
}

const anchorElement = createElement('a', {}, []);
BODY.append(anchorElement);

anchorElement.addEventListener('click', async (e) => {
expect(shouldProcessLinkClick(e));
done();
});

anchorElement.click();
});
});

0 comments on commit 9d41a9a

Please sign in to comment.