#add expect as global

1 messages · Page 1 of 1 (latest)

livid horizon
#

Hi,
I have cypress for e2e testing and itest for unit tests setup in my react app project. Previously, it was jest and now I am migrating to vitest.

I have configured my app to run on vitest. But for my unit tests expect is getting globally imported from cypress instead of vitest. How can I make expect(from vitest) to be global as well so that I don't have to import it individually in each file?
This is my tsconfig.json and vite.config.ts

{ "compilerOptions": { "target": "ESNext", "lib": ["dom", "dom.iterable", "esnext", "es5"], "allowJs": true, "skipLibCheck": true, "esModuleInterop": true, "allowSyntheticDefaultImports": true, "strict": true, "forceConsistentCasingInFileNames": true, "noFallthroughCasesInSwitch": true, "module": "ESNext", "moduleResolution": "node", "resolveJsonModule": true, "isolatedModules": true, "noEmit": true, "jsx": "react-jsx", "baseUrl": "src", "noImplicitAny": true, "downlevelIteration": true, "types": ["cypress", "node", "vitest", "vitest/globals"] }, "include": ["src", "**/*.ts"] }

export default defineConfig({ plugins: [ react(), tsconfigPaths(), nodePolyfills({ globals: { Buffer: true, global: true, process: true, }, })], test: { globals: true, environment: "jsdom", setupFiles: "./src/setupTests.ts", } })

fluid bough
#

Your Vitest config looks correct for global types setup

#

But now there are two global "expect" - one from cypress, one from Vitest