Skip to content

Commit 0782cac

Browse files
committed
mock http.ClientRequest.prototype.setTimeout
1 parent dfee3cc commit 0782cac

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/__test__/Request.test.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -510,16 +510,15 @@ test('request: fetch() unsuccessful (timeout)', async () => {
510510

511511
})
512512

513-
const oldSetTimeout = http.ClientRequest.prototype.setTimeout;
513+
const originalSetTimeout = http.ClientRequest.prototype.setTimeout;
514514

515515
beforeAll(() => {
516516
// trigger a timeout without waiting much real time
517517
http.request.prototype.setTimeout = function(_timeout: number, cb?: () => void) {
518-
cb && setTimeout(cb, 0)
519-
return this
518+
return originalSetTimeout(0, cb)
520519
}
521520
})
522521

523522
afterAll(() => {
524-
http.request.prototype.setTimeout = oldSetTimeout
523+
http.request.prototype.setTimeout = originalSetTimeout
525524
})

0 commit comments

Comments
 (0)