jest-extended
jest-extended copied to clipboard
Add matchers for asserting that a promise has resolved or rejected (regardless of value)
Feature Request
Description: I would like a way to be able to check if a promise resolves or rejects, regardless of the value that it produces, or if it even produces a value, it is irrelevant. In particular, i want to easily be able to easily check to make sure that a promise was not rejected. I don't care at all if it actually sent an error, undefined, or whatever, I just want to make sure it was not rejected. Previous issue referenced at facebook/jest#5248
Possible solution: I would like a matcher like expect(promise).toResolve() or expect(promise).not.toReject(). Right now, as far as I can tell, there is no simple way to go about asserting whether or not a promise has resolved or rejected without taking into account its value. I want to be able to assert this without regard to its response, the error message, or otherwise. @SimenB said that facebook/jest#5919 adds support for async matchers, so this should be much more feasible now.
This has been sat here for a while, tbh I'm not sure how to go about this, nor how I feel about it either. I say this because I'm on 10% time at work and figured I'm free enough to kick-start this conversation (hopefully). https://github.com/mattphillips/babel-jest-assertions is potentially a solution, as this enforces the expect to be called in the advent of a none existent resolve/reject.
I was thinking can we tie into the timeout for a test in the jest config and expect it to be completed by the time that timeout comes, (i think 5 seconds default?)
@mattphillips ping π
Hey guys sorry for the delay in coming back to this, Iβm currently holidaying and AFK for the most-part.
@benjaminkay93 I think this should be possible with the new async matchers. Iβd imagine it would be a similar implementation to Jestβs .resolves API.
okay, im happy to give this a go if nobody else wants to, are there any examples of async custom matchers knockin about? would make life easier, ill ofc have a google too
@benjaminkay93 check out the expect extend docs there is an async section
https://jestjs.io/docs/en/expect#expectextendmatchers
Let me know how you get on with this, if you need a hand Iβll be back from my travels in about a week so can look into this too then :smile:
sweet cheers matt, enjoy your hols! π
Would it be possible to return the error message when toResolve()
fails ?
Now, it is quite hard to debug without running extra manual tests.
Note: resolves.not.toThrow()
works
Hi there, congratulations for this awesome library! I was just browsing through this issue, and I have the impression it has since been implemented? Check .toResolve()/.toReject()