Skip to content

Commit

Permalink
docs: mock different endpoints in a single file (#1589)
Browse files Browse the repository at this point in the history
  • Loading branch information
ritvik130 committed Aug 3, 2022
1 parent e1e1638 commit 2f4b3b6
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 2f4b3b6

Please sign in to comment.