Jest: [Feature] mock function promise support

Created on 14 Oct 2016  Â·  8Comments  Â·  Source: facebook/jest

Hello Team Jest,

Thanks for working so hard on this wonderful test runner. I just recently gave jest another spin after trying it when it first came out, and I love all the progress you all have made.

I have a simple feature request.
One thing I am missing from mocha/sinon is nicer mocks for functions that return promises.
I specifically used to use http://npmrepo.com/sinon-as-promised for easy promise mocking.

I'd love to see mock functions to have .mockResolveValue(val) and .mockRejectValue(err) versus .mockReturnValue(Promise.resolve(val)) and .mockReturnValue(Promise.reject(err))

Thoughts?

Question

Most helpful comment

Sure I would love to implement this. Seems simple enough.

All 8 comments

Hi @tjmehta, happy to review PR if you're interested in implementing that :)

Sure I would love to implement this. Seems simple enough.

Closing this in favour of PR

I'll keep this open for now, we may want to discuss this a bit more.

Oh, ok, thought we'd do it in a PR

Sorry, just haven't thought about this myself much yet but I'm thinking this issue may go beyond the PR a bit. We'll see :)

I plan on following up with the PR today. So let's see where it goes. Sorry
for the delay!
On Sat, Jan 7, 2017 at 1:58 AM Christoph Pojer notifications@github.com
wrote:

Sorry, just haven't thought about this myself much yet but I'm thinking
this issue may go beyond the PR a bit. We'll see :)

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/facebook/jest/issues/1930#issuecomment-271074262, or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAnFF4h6nOPP5TxhDEvtHFtR8uzPfP45ks5rP2HNgaJpZM4KWrwX
.

Don't be sorry, thanks!

Was this page helpful?
0 / 5 - 0 ratings