-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Closed
Labels
Description
Do you want to request a feature or report a bug?
Feature
What is the current behavior?
Custom matchers must return an object of the form:
{ pass: [boolean], message: [string|function] }.
It would be helpful to support matchers that return a Promise, thereby allowing custom matchers that can utilize async/await to flush pending Promises.
This may be of use for folks waiting on #2157.
I'd like to be able to have a matcher something of the form (though this is a contrived example):
// matcher
async function toAwaitAsync (received, arg) {
const pass = await received(arg)
return { pass, message: 'expected one thing, got another' }
}
// thing to test
async function doStuff (arg) {
await Promise.resolve()
return !!(arg)
}
// test
test('something async', () => {
expect(doStuff).toAwaitAsync('foo')
})sbekrin, dowsanjack and therynamo