Skip to content

Commit bb6775b

Browse files
committed
Gate AbortController tests
We also test Node.js 14 which doesn't support AbortController
1 parent 25d1857 commit bb6775b

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

src/__tests__/waitForNode.js

+22-16
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ test('ensures the given callback is a function', () => {
7474
)
7575
})
7676

77+
const testAbortController =
78+
typeof AbortController === 'undefined' ? test.skip : test
79+
7780
describe('using fake modern timers', () => {
7881
beforeEach(() => {
7982
jest.useFakeTimers('modern')
@@ -220,7 +223,7 @@ describe('using fake modern timers', () => {
220223
`)
221224
})
222225

223-
test('can be aborted with an AbortSignal', async () => {
226+
testAbortController('can be aborted with an AbortSignal', async () => {
224227
const callback = jest.fn(() => {
225228
throw new Error('not done')
226229
})
@@ -238,21 +241,24 @@ describe('using fake modern timers', () => {
238241
expect(callback).toHaveBeenCalledTimes(2)
239242
})
240243

241-
test('does not even ping if the signal is already aborted', async () => {
242-
const callback = jest.fn(() => {
243-
throw new Error('not done')
244-
})
245-
const controller = new AbortController()
246-
controller.abort('Bailing out')
244+
testAbortController(
245+
'does not even ping if the signal is already aborted',
246+
async () => {
247+
const callback = jest.fn(() => {
248+
throw new Error('not done')
249+
})
250+
const controller = new AbortController()
251+
controller.abort('Bailing out')
247252

248-
const waitForError = waitFor(callback, {
249-
signal: controller.signal,
250-
})
253+
const waitForError = waitFor(callback, {
254+
signal: controller.signal,
255+
})
251256

252-
await expect(waitForError).rejects.toThrowErrorMatchingInlineSnapshot(
253-
`Aborted: Bailing out`,
254-
)
255-
// Just the initial check
256-
expect(callback).toHaveBeenCalledTimes(1)
257-
})
257+
await expect(waitForError).rejects.toThrowErrorMatchingInlineSnapshot(
258+
`Aborted: Bailing out`,
259+
)
260+
// Just the initial check
261+
expect(callback).toHaveBeenCalledTimes(1)
262+
},
263+
)
258264
})

0 commit comments

Comments
 (0)