I migrated my codebase from cra to vite. Then added vitest to it. Everything is working fine. Test cases are not breaking because of configuration. One thing which is irritating me the most is while performing the assertion for example expect(getByText(text)).toBeInTheDocument();
. I am expecting my VS code to provide suggestions of all the possible matchers that exist including the .toBeVisible()
. But somehow not getting the same.
What I have tried so far?
- Created a new Vite project and added vitest and the configuration. Working fine! It is showing all the matchers in suggestion.
- Added
@types/jest
to my dev dependencies and updated the configuration it is showing all the suggestions in my existing project. But this is not showing.toBeVisible()
in suggestion.
I believe the second point is not the intented way to achieve the same. First point is going to take a lot of time to add all the existing files to new repo.
vitest.config.js
test: {
globals: true,
environment: "jsdom",
setupFiles: "./src/config/vite/vitest.setup.js",
coverage: {
reporter: ["text", "html"],
exclude: ["node_modules/", "./src/config/vite/vitest.setup.js"],
},
css: true,
},
vitest.setup.js
import "@testing-library/jest-dom";
Please suggest if anything could be done over here as many may happen to face this situation who are migrating from cra to vite and migrating jest to vitest. Thanks in advance!
adding import
{ expect, describe } from "vitest";
to each test file will solve the issue, but I still don't know how to implement it globally.