Skip to content

Commit

Permalink
docs: mock different endpoints in a single file (nodejs#1589)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritvik130 authored and crysmags committed Feb 27, 2024
1 parent f6c6a3f commit cfd9517
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions docs/api/MockAgent.md
Expand Up @@ -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

Expand Down

0 comments on commit cfd9517

Please sign in to comment.