diff --git a/src/vitest.setup.js b/src/vitest.setup.js new file mode 100644 index 000000000..493ad8515 --- /dev/null +++ b/src/vitest.setup.js @@ -0,0 +1,11 @@ +// jest-dom adds custom jest matchers for asserting on DOM nodes. +// allows you to do things like: +// expect(element).toHaveTextContent(/react/i) +// learn more: https://github.com/testing-library/jest-dom +import '@testing-library/jest-dom'; + +import mswServer from 'api-mocks/msw-server'; + +beforeAll(() => mswServer.listen()); +afterEach(() => mswServer.resetHandlers()); +afterAll(() => mswServer.close()); diff --git a/vite.config.mts b/vite.config.mts index 1e9c1e8d0..228685f04 100644 --- a/vite.config.mts +++ b/vite.config.mts @@ -1,3 +1,4 @@ +/// // https://vitejs.dev/config/ import react from '@vitejs/plugin-react'; import lodashTemplate from 'lodash/template'; @@ -30,4 +31,9 @@ export default defineConfig({ }, }, ], + test: { + environment: 'jsdom', + globals: true, // for compatibility with jest + setupFiles: ['./src/vitest.setup.js'], + }, });