We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
nock.disableNetConnect
1 parent b29751f commit 7ab2027Copy full SHA for 7ab2027
src/vitest.setup.ts
@@ -1,8 +1,17 @@
1
-// Vitest setup file
2
-import "./utils/path" // Import to enable String.prototype.toPosix()
+import nock from "nock"
3
4
-// Mock fs/promises for tests that need it
5
-import { vi } from "vitest"
+import "./utils/path" // Import to enable String.prototype.toPosix().
6
7
-// Global mocks that many tests expect
+// Disable network requests by default for all tests.
+nock.disableNetConnect()
+
8
+export function allowNetConnect(host?: string | RegExp) {
9
+ if (host) {
10
+ nock.enableNetConnect(host)
11
+ } else {
12
+ nock.enableNetConnect()
13
+ }
14
+}
15
16
+// Global mocks that many tests expect.
17
global.structuredClone = global.structuredClone || ((obj: any) => JSON.parse(JSON.stringify(obj)))
0 commit comments