Testing with Vitest
This guide will help you setup Vitest and React Testing Library for your project. Note that this guide intended for projects that use Vite as a bundler, if you are using other frameworks/bundlers, it is recommended to use Jest instead.
Install vitest and react testing library:
If you want to run tests from your IDE, install one of the extensions.
Add vitest configuration to your Vite config file:
vitest.setup.mjs file in your project root and add the following code to it:
The code above mocks
ResizeObserver APIs that are not available
jsdom environment but are required by some Mantine components.
Optionally you can add vitest scripts to your
It is usually more convenient to export all
@testing-library/* functions that you are planning to use
Then you should import all testing utilities from
./testing-utils instead of
You can find an example with a full Vitest setup in mantine-vite-template.