Skip to content

Commit dfee3cc

Browse files
author
Dan Skinner
committed
mock http.ClientRequest.prototype.setTimeout
1 parent 2e6631f commit dfee3cc

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/__test__/Request.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,4 +507,19 @@ test('request: fetch() unsuccessful (timeout)', async () => {
507507
expect(e.isRetryable).toBe(true)
508508
expect(e.code).toBe(NetworkErrorCode.TIMEOUT)
509509
}
510+
510511
})
512+
513+
const oldSetTimeout = http.ClientRequest.prototype.setTimeout;
514+
515+
beforeAll(() => {
516+
// trigger a timeout without waiting much real time
517+
http.request.prototype.setTimeout = function(_timeout: number, cb?: () => void) {
518+
cb && setTimeout(cb, 0)
519+
return this
520+
}
521+
})
522+
523+
afterAll(() => {
524+
http.request.prototype.setTimeout = oldSetTimeout
525+
})

0 commit comments

Comments
 (0)