Skip to content

Commit

Permalink
test(async): exclude test for .finally when it isn't supported in the…
Browse files Browse the repository at this point in the history
… runtime
  • Loading branch information
cahilfoley committed Nov 29, 2019
1 parent cdb52d9 commit 9214cc5
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/async/CancelablePromise.test.ts
Expand Up @@ -31,16 +31,20 @@ describe('CancelablePromise', () => {
expect(onRejected).toHaveBeenCalledWith('some error')
})

it('completes like a regular promise when not canceled', async () => {
const cancelable = createPromise()
const { onFulfilled, onRejected, onFinally } = createMockFns()
await cancelable.then(onFulfilled)
await cancelable.catch(onRejected)
await cancelable.finally(onFinally)
expect(onFulfilled).toHaveBeenCalledWith('hello world')
expect(onRejected).not.toHaveBeenCalled()
expect(onFinally).toHaveBeenCalled()
})
if (typeof Promise.prototype.finally === 'function') {
it('completes like a regular promise when not canceled', async () => {
const cancelable = createPromise()
const { onFulfilled, onRejected, onFinally } = createMockFns()

await cancelable.then(onFulfilled)
await cancelable.catch(onRejected)
await cancelable.finally(onFinally)

expect(onFulfilled).toHaveBeenCalledWith('hello world')
expect(onRejected).not.toHaveBeenCalled()
expect(onFinally).toHaveBeenCalled()
})
}

it('stringifies to the string [object CancelablePromise]', () => {
const cancelable = createPromise()
Expand Down

0 comments on commit 9214cc5

Please sign in to comment.