Skip to content

Commit

Permalink
chore: [capricorn86#1464] Add failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
amitdahan committed Jun 17, 2024
1 parent ef2dfea commit 80bbc41
Showing 1 changed file with 10 additions and 0 deletions.
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 80bbc41

Please sign in to comment.