I'm trying to run this jestJS unit-test, but I do get TypeError: Promise resolver undefined is not a function
. What am I doing wrong?
it('_onSubmit() should throw error if data is missing', (done) => {
const createUserMutation = () => new Promise()
const wrapper = shallow(<CreateAccount createUserMutation={createUserMutation} />)
wrapper.update().find(Form).simulate('submit', {
preventDefault: () => {}
})
createUserMutation.resolve().then(() => {
expect(console.error).toHaveBeenCalled()
done()
})
})
new Promise()
is trying to create a promise without an executor function*. The correct usage is to pass in a function that accepts up to two parameters (resolve
and reject
), e.g.:
var p = new Promise((resolve, reject) => {
// ...code that does something, ultimately calls either resolve or reject
});
More on MDN:
Promise
constructorLater, you appear to be trying to call resolve
on the promise instance. You can't do that either (unless you're not using standard promises). You resolve a promise using the resolve
function passed into the executor. (I tried to modify your code for you, but too much context info is required.)
* I'm surprised to see V8's error message say "resolver function" but I've verified it does. The spec calls it an executor, and I would have thought a "resolver functioN" would be the function the Promise
constructor passes as the first argument to it...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With