
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
@ionic/react-test-utils
Advanced tools
This is a set of helper methods to make testing easier in Ionic React with React Testing Library and Jest.
yarn add -D @ionic/react-test-utils
or
npm install --dev @ionic/react-test-utils
ionFireEvent
extends Testing Library's fireEvent
by adding the custom ion*
events. This can be used as a drop in replacement for fireEvent
or used in conjunction with.
import { ionFireEvent as fireEvent } from '@ionic/react-test-utils';
...
fireEvent.ionChange(element, 'my text');
This method mocks out certain Ionic components that have issues rendering in JSDOM. To use it, open up setupTests.ts
and add this to the file:
import { mockIonicReact } from '@ionic/react-test-utils';
mockIonicReact();
If you are using Ionic v6, you will also need to call setupIonicReact
:
import { mockIonicReact } from '@ionic/react-test-utils';
import { setupIonicReact } from '@ionic/react';
setupIonicReact();
mockIonicReact();
This function waits for Ionic React to be fully initialized. Use this in any test that renders Ionic components, to ensure the rendered markup has all classes etc. that Ionic adds at runtime.
import { render } from '@testing-library/react';
import { waitForIonicReact } from '@ionic/react-test-utils';
import MyComponent from './MyComponent';
describe('<MyComponent />', () => {
it('renders consistently', async () => {
const { baseElement } = render(<MyComponent/>);
await waitForIonicReact();
expect(baseElement).toMatchSnapshot();
});
});
waitForIonicReact
waits for the DOM to be stable, meaning no markup has changed for a certain period of time. This period is determined by the first parameter, timeout
, which defaults to 750 milliseconds. There is also a global timeout determined by the second parameter, maxWaitTime
. This defaults to 5000 milliseconds (five seconds) and, if hit, will cause the function to fail early. If you find your tests are running too slow or not detecting all Ionic behaviors, try tweaking these values.
FAQs
Test utilities for Ionic React
The npm package @ionic/react-test-utils receives a total of 3,363 weekly downloads. As such, @ionic/react-test-utils popularity was classified as popular.
We found that @ionic/react-test-utils demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 26 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.