From cfd9517cb6f45ba53e159de5ef59b9bc282c34e8 Mon Sep 17 00:00:00 2001 From: Ritvik Johar <73025710+ritvik130@users.noreply.github.com> Date: Wed, 3 Aug 2022 17:00:37 -0400 Subject: [PATCH] docs: mock different endpoints in a single file (#1589) --- docs/api/MockAgent.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/docs/api/MockAgent.md b/docs/api/MockAgent.md index 5c8eda24937..85ae69046e7 100644 --- a/docs/api/MockAgent.md +++ b/docs/api/MockAgent.md @@ -177,6 +177,23 @@ for await (const data of result2.body) { console.log('data', data.toString('utf8')) // data hello } ``` +#### Example - Mock different requests within the same file +```js +const { MockAgent, setGlobalDispatcher } = require('undici'); +const agent = new MockAgent(); +agent.disableNetConnect(); +setGlobalDispatcher(agent); +describe('Test', () => { + it('200', async () => { + const mockAgent = agent.get('http://test.com'); + // your test + }); + it('200', async () => { + const mockAgent = agent.get('http://testing.com'); + // your test + }); +}); +``` #### Example - Mocked request with query body, headers and trailers