forked from nodejs/undici
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmock-scope.test.js
More file actions
29 lines (21 loc) · 753 Bytes
/
mock-scope.test.js
File metadata and controls
29 lines (21 loc) · 753 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const { MockAgent, setGlobalDispatcher, request } = require('../../index')
/* global afterAll, expect, it, AbortController */
const mockAgent = new MockAgent()
afterAll(async () => {
await mockAgent.close()
})
it('Jest works with MockScope.delay - issue #1327', async () => {
mockAgent.disableNetConnect()
setGlobalDispatcher(mockAgent)
const mockPool = mockAgent.get('http://localhost:3333')
mockPool.intercept({
path: '/jest-bugs',
method: 'GET'
}).reply(200, 'Hello').delay(100)
const ac = new AbortController()
setTimeout(() => ac.abort(), 5)
const promise = request('http://localhost:3333/jest-bugs', {
signal: ac.signal
})
await expect(promise).rejects.toThrowError('This operation was aborted')
}, 1000)