You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: exercises/03.best-practices/03.problem.network-mocking/README.mdx
+5-5
Original file line number
Diff line number
Diff line change
@@ -48,7 +48,7 @@ export const handlers = []
48
48
49
49
```ts filename=src/mocks/browser.ts
50
50
import { setupWorker } from'msw/browser'
51
-
import { handlers } from'./handlers.js'
51
+
import { handlers } from'./handlers'
52
52
53
53
exportconst worker =setupWorker(...handlers)
54
54
```
@@ -96,7 +96,7 @@ import { test as testBase } from 'vitest'
96
96
```ts filename=test-extend.ts add=3
97
97
import { testastestBase } from'vitest'
98
98
99
-
exportconst test =testBase.extend()
99
+
exportconst test =testBase.extend({})
100
100
```
101
101
102
102
> :owl: Calling `.extend()` allows you to put _custom properties_ you can then access on the `test()` function.
@@ -117,7 +117,7 @@ Right now, the `worker` property has an array of two elements: `fixture` and `op
117
117
118
118
```ts filename=test-extend.ts add=2,6-14
119
119
import { testastestBase } from'vitest'
120
-
import { worker } from'./src/mocks/browser.js'
120
+
import { worker } from'./src/mocks/browser'
121
121
122
122
exportconst test =testBase.extend({
123
123
worker: [
@@ -144,7 +144,7 @@ await worker.start({
144
144
})
145
145
```
146
146
147
-
Here, you are starting the worker that enables request mocking in MSW. You are referencing the same `worker` object you've configured previously in `src/mocks/browser.js`.
147
+
Here, you are starting the worker that enables request mocking in MSW. You are referencing the same `worker` object you've configured previously in `src/mocks/browser.ts`.
148
148
149
149
```ts nonumber
150
150
awaituse(worker)
@@ -162,7 +162,7 @@ worker.resetHandlers()
162
162
163
163
This line makes sure that any mocks you add in individual tests are _reset_ between them. This achieves scope isolation and prevents network overrides from leaking to irrelevant tests.
0 commit comments