Vitest
Migrated from Jest to Vitest
Together with the FE codebase migrating to Vite we have also migrated from Jest to Vitest. Since Vitest is Jest compatible all tests are written as usual, still utilising the common testing library patterns. For the vitest API reference check out the vitest docs.
How to run specific tests
Single test: yarn test run ./path-to-test.test.jsx
Related tests: yarn test related ./specific-forlder/
Testing plugin
In order to make it easier and more consistent to write good tests, following best practices to match selectors consider adding the following plugin to your VSCODE.
vscode-testing-playground
describe('example test', () => {
it.('renders example component', () => {
render(<ExampleComponent />)
screen.logTestingPlaygroundURL(); // add this after your tests render
expect(screen.getByText('example test')).toBeInTheDocument();
})
})After the above your terminal will log out a testing playground URL where you can see a copy of your mounted component and see which selectors are available to you in an interactive view. VSCODE can even open the preview directly if configured.
