Simple addon to your vitest, that will break tests if any of them make a network request.
With npm:
npm i -D vitest-offline
With pnpm:
pnpm add -D vitest-offline
With yarn:
yarn add vitest-offline --dev
In your vitest setup file add following code:
// e.g. src/setupTests.ts
import { setupNetworkInterceptor } from "vitest-offline";
setupNetworkInterceptor();
Import to your Vite config file:
// vitest.config.mts or vite.config.mts
export default defineConfig({
test: {
...
// make sure it is correct path to your setupTests file
setupFiles: "./src/setupTests.ts",
},
});