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: deps/undici/src/docs/best-practices/mocking-request.md
+9-9
Original file line number
Diff line number
Diff line change
@@ -1,22 +1,22 @@
1
1
# Mocking Request
2
2
3
-
Undici have its own mocking [utility](../api/MockAgent.md). It allow us to intercept undici HTTP request and return mocked value instead. It can be useful for testing purposes.
3
+
Undici has its own mocking [utility](../api/MockAgent.md). It allow us to intercept undici HTTP requests and return mocked values instead. It can be useful for testing purposes.
const { body } =awaitrequest('http://localhost:3000/bank-transfer',
13
13
{
14
14
method:'POST',
15
15
headers: {
16
16
'X-TOKEN-SECRET':'SuperSecretToken',
17
17
},
18
18
body:JSON.stringify({
19
-
recepient,
19
+
recipient,
20
20
amount
21
21
})
22
22
}
@@ -48,7 +48,7 @@ mockPool.intercept({
48
48
'X-TOKEN-SECRET':'SuperSecretToken',
49
49
},
50
50
body:JSON.stringify({
51
-
recepient:'1234567890',
51
+
recipient:'1234567890',
52
52
amount:'100'
53
53
})
54
54
}).reply(200, {
@@ -77,7 +77,7 @@ Explore other MockAgent functionality [here](../api/MockAgent.md)
77
77
78
78
## Debug Mock Value
79
79
80
-
When the interceptor we wrote are not the same undici will automatically call real HTTP request. To debug our mock value use `mockAgent.disableNetConnect()`
80
+
When the interceptor and the request options are not the same, undici will automatically make a real HTTP request. To prevent real requests from being made, use `mockAgent.disableNetConnect()`:
0 commit comments