Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
capricorn86 authored Jun 20, 2024
2 parents 221e22b + 3504a93 commit fbb71ce
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
4 changes: 1 addition & 3 deletions packages/happy-dom/src/cookie/CookieContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ export default class CookieContainer implements ICookieContainer {
public addCookies(cookies: ICookie[]): void {
const indexMap: { [k: string]: number } = {};
const getKey = (cookie: ICookie): string =>
`${cookie.key}-${cookie.originURL.hostname}-${
cookie.originURL.pathname
}-${typeof cookie.value}`;
`${cookie.key}-${cookie.originURL.hostname}-${cookie.path}-${typeof cookie.value}`;

// Creates a map of cookie key, domain, path and value to index.
for (let i = 0, max = this.#cookies.length; i < max; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,7 @@ export default class HTMLAnchorElement extends HTMLElement implements IHTMLHyper
if (
event.type === 'click' &&
event instanceof MouseEvent &&
(event.eventPhase === EventPhaseEnum.atTarget ||
event.eventPhase === EventPhaseEnum.bubbling) &&
event.eventPhase === EventPhaseEnum.none &&
!event.defaultPrevented
) {
const href = this.href;
Expand Down
10 changes: 10 additions & 0 deletions packages/jest-environment/test/react/React.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,14 @@ describe('React', () => {
await TESTING_LIBRARY_USER.click(button);
expect(document.querySelector('p span').textContent).toBe('test');
});

it('Can `preventDefault` to prevent navigation with React click listener on an anchor tag', async () => {
location.href = 'http://localhost/';
const { getByRole } = ReactTestingLibrary.render(
<a href="http://example.com" onClick={(ev) => ev.preventDefault()} />
);
expect(document.location.href).toBe('http://localhost/');
await TESTING_LIBRARY_USER.click(getByRole('link'));
expect(document.location.href).toBe('http://localhost/');
});
});

0 comments on commit fbb71ce

Please sign in to comment.