Skip to content

Commit

Permalink
Gate AbortController tests
Browse files Browse the repository at this point in the history
We also test Node.js 14 which doesn't support AbortController
  • Loading branch information
eps1lon committed Feb 9, 2023
1 parent 25d1857 commit bb6775b
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/__tests__/waitForNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ test('ensures the given callback is a function', () => {
)
})

const testAbortController =
typeof AbortController === 'undefined' ? test.skip : test

describe('using fake modern timers', () => {
beforeEach(() => {
jest.useFakeTimers('modern')
Expand Down Expand Up @@ -220,7 +223,7 @@ describe('using fake modern timers', () => {
`)
})

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

test('does not even ping if the signal is already aborted', async () => {
const callback = jest.fn(() => {
throw new Error('not done')
})
const controller = new AbortController()
controller.abort('Bailing out')
testAbortController(
'does not even ping if the signal is already aborted',
async () => {
const callback = jest.fn(() => {
throw new Error('not done')
})
const controller = new AbortController()
controller.abort('Bailing out')

const waitForError = waitFor(callback, {
signal: controller.signal,
})
const waitForError = waitFor(callback, {
signal: controller.signal,
})

await expect(waitForError).rejects.toThrowErrorMatchingInlineSnapshot(
`Aborted: Bailing out`,
)
// Just the initial check
expect(callback).toHaveBeenCalledTimes(1)
})
await expect(waitForError).rejects.toThrowErrorMatchingInlineSnapshot(
`Aborted: Bailing out`,
)
// Just the initial check
expect(callback).toHaveBeenCalledTimes(1)
},
)
})

0 comments on commit bb6775b

Please sign in to comment.