From b51a566de47d631a690a8fe5d44da18d04cbbcf3 Mon Sep 17 00:00:00 2001 From: Fabian Meyer <3982806+meyfa@users.noreply.github.com> Date: Mon, 18 Jul 2022 15:41:09 +0200 Subject: [PATCH] docs: Fix spelling/grammar in "Mocking Request" --- docs/best-practices/mocking-request.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/docs/best-practices/mocking-request.md b/docs/best-practices/mocking-request.md index b98a450a32e..69543927444 100644 --- a/docs/best-practices/mocking-request.md +++ b/docs/best-practices/mocking-request.md @@ -1,6 +1,6 @@ # Mocking Request -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. +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. Example: @@ -8,7 +8,7 @@ Example: // bank.mjs import { request } from 'undici' -export async function bankTransfer(recepient, amount) { +export async function bankTransfer(recipient, amount) { const { body } = await request('http://localhost:3000/bank-transfer', { method: 'POST', @@ -16,7 +16,7 @@ export async function bankTransfer(recepient, amount) { 'X-TOKEN-SECRET': 'SuperSecretToken', }, body: JSON.stringify({ - recepient, + recipient, amount }) } @@ -48,7 +48,7 @@ mockPool.intercept({ 'X-TOKEN-SECRET': 'SuperSecretToken', }, body: JSON.stringify({ - recepient: '1234567890', + recipient: '1234567890', amount: '100' }) }).reply(200, { @@ -77,7 +77,7 @@ Explore other MockAgent functionality [here](../api/MockAgent.md) ## Debug Mock Value -When the interceptor we wrote are not the same undici will automatically call real HTTP request. To debug our mock value use `mockAgent.disableNetConnect()` +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()`: ```js const mockAgent = new MockAgent(); @@ -89,7 +89,7 @@ mockAgent.disableNetConnect() const mockPool = mockAgent.get('http://localhost:3000'); mockPool.intercept({ - path: '/bank-tanfer', + path: '/bank-transfer', method: 'POST', }).reply(200, { message: 'transaction processed' @@ -103,7 +103,7 @@ const badRequest = await bankTransfer('1234567890', '100') ## Reply with data based on request -If the mocked response needs to be dynamically derived from the request parameters, you can provide a function instead of an object to `reply` +If the mocked response needs to be dynamically derived from the request parameters, you can provide a function instead of an object to `reply`: ```js mockPool.intercept({ @@ -113,7 +113,7 @@ mockPool.intercept({ 'X-TOKEN-SECRET': 'SuperSecretToken', }, body: JSON.stringify({ - recepient: '1234567890', + recipient: '1234567890', amount: '100' }) }).reply(200, (opts) => { @@ -129,7 +129,7 @@ in this case opts will be { method: 'POST', headers: { 'X-TOKEN-SECRET': 'SuperSecretToken' }, - body: '{"recepient":"1234567890","amount":"100"}', + body: '{"recipient":"1234567890","amount":"100"}', origin: 'http://localhost:3000', path: '/bank-transfer' }