First, make sure that you have the correct peer dependencies installed.
To integrate with your tests, currently, you will need copy from the matcher and set it by adding a setupFilesAfterEnv
in jest.config.js
. Then, you'll need to extend expect by using expect.extend
in that afterEnv
file.
See how this is done in this by looking at our jest.config.js
and afterEnv.ts
.
Finds a matching React element in a shallow render
it('finds React elements', () => {
expect(<button type="button">Test</button>).toContainReactElement('button');
});
The second argument can be used to specify props.
it('finds React elements with correct props', () => {
expect(<button type="button">Test</button>).toContainReactElement('button', {
type: 'button',
});
});
- Set up on NPM registry
- Add more rules