AVA 4 removing callback support? #2752
-
|
While going through the AVA docs found here, it says that
Searching in Google about this did not turn up any results, although I didn't search too far. I'm curious, what is the reason for this? What will be the alternatives for callback testing? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
Yes, it's being removed. Modern APIs tend to use promises, not callbacks, and those are best tested using You can use 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.) |
Beta Was this translation helpful? Give feedback.
-
|
So how are we going to test a socket app? |
Beta Was this translation helpful? Give feedback.
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
promisifyfrom the built-inutilmodule to wrap a callback-taking API, or the test implementation itself:(I haven't tested this.)