Skip to content

Commit b51a566

Browse files
authored
docs: Fix spelling/grammar in "Mocking Request"
1 parent 784c6b4 commit b51a566

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

docs/best-practices/mocking-request.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
# Mocking Request
22

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.
44

55
Example:
66

77
```js
88
// bank.mjs
99
import { request } from 'undici'
1010

11-
export async function bankTransfer(recepient, amount) {
11+
export async function bankTransfer(recipient, amount) {
1212
const { body } = await request('http://localhost:3000/bank-transfer',
1313
{
1414
method: 'POST',
1515
headers: {
1616
'X-TOKEN-SECRET': 'SuperSecretToken',
1717
},
1818
body: JSON.stringify({
19-
recepient,
19+
recipient,
2020
amount
2121
})
2222
}
@@ -48,7 +48,7 @@ mockPool.intercept({
4848
'X-TOKEN-SECRET': 'SuperSecretToken',
4949
},
5050
body: JSON.stringify({
51-
recepient: '1234567890',
51+
recipient: '1234567890',
5252
amount: '100'
5353
})
5454
}).reply(200, {
@@ -77,7 +77,7 @@ Explore other MockAgent functionality [here](../api/MockAgent.md)
7777

7878
## Debug Mock Value
7979

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()`:
8181

8282
```js
8383
const mockAgent = new MockAgent();
@@ -89,7 +89,7 @@ mockAgent.disableNetConnect()
8989
const mockPool = mockAgent.get('http://localhost:3000');
9090

9191
mockPool.intercept({
92-
path: '/bank-tanfer',
92+
path: '/bank-transfer',
9393
method: 'POST',
9494
}).reply(200, {
9595
message: 'transaction processed'
@@ -103,7 +103,7 @@ const badRequest = await bankTransfer('1234567890', '100')
103103

104104
## Reply with data based on request
105105

106-
If the mocked response needs to be dynamically derived from the request parameters, you can provide a function instead of an object to `reply`
106+
If the mocked response needs to be dynamically derived from the request parameters, you can provide a function instead of an object to `reply`:
107107

108108
```js
109109
mockPool.intercept({
@@ -113,7 +113,7 @@ mockPool.intercept({
113113
'X-TOKEN-SECRET': 'SuperSecretToken',
114114
},
115115
body: JSON.stringify({
116-
recepient: '1234567890',
116+
recipient: '1234567890',
117117
amount: '100'
118118
})
119119
}).reply(200, (opts) => {
@@ -129,7 +129,7 @@ in this case opts will be
129129
{
130130
method: 'POST',
131131
headers: { 'X-TOKEN-SECRET': 'SuperSecretToken' },
132-
body: '{"recepient":"1234567890","amount":"100"}',
132+
body: '{"recipient":"1234567890","amount":"100"}',
133133
origin: 'http://localhost:3000',
134134
path: '/bank-transfer'
135135
}

0 commit comments

Comments
 (0)