Skip to content

AVA 4 removing callback support? #2752

Answered by novemberborn
Devwulf asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, it's being removed. Modern APIs tend to use promises, not callbacks, and those are best tested using async/await. Callback tests required a lot of duplication in our type definitions. It didn't seem worth the maintenance cost.

You can use promisify from the built-in util module to wrap a callback-taking API, or the test implementation itself:

import { promisify } from 'node:util'
import test from 'ava'

const withCallback = fn => async t => {
  await promisify(fn)(t)
  t.pass() // There must be at least one passing assertion for the test to pass
}

test('callbackish', withCallback((t, end) => {
  someCallbackThing(end)
})

(I haven't tested this.)

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@Devwulf
Comment options

Answer selected by Devwulf
Comment options

You must be logged in to vote
1 reply
@sindresorhus
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants