question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

rejects doesn't work

See original GitHub issue

I’ve tried to use the await expect(...).rejects function as documented in https://facebook.github.io/jest/docs/en/tutorial-async.html

However rejects it simply doesn’t work at all.

This is an error example:

    expect(received).rejects.toHaveProperty()

    Expected received Promise to reject, instead it resolved to value
      undefined

      at Object.<anonymous> (node_modules/expect/build/index.js:182:9)
      at step (node_modules/expect/build/index.js:43:727)
      at node_modules/expect/build/index.js:43:887

Of course the promise in that case was a rejection but it wasn’t seen as so.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
SimenBcommented, Feb 2, 2018

That example works correctly: https://repl.it/repls/HumongousKnottyMilkweedbug. It fails because the toEqual part is wrong, but it rejects correctly - there is no

Expected received Promise to reject, instead it resolved to value
      undefined
1reaction
alem0larscommented, Feb 1, 2018

@SimenB I’ve added it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Promise reject not working inside of callback - Stack Overflow
I'm following the common pattern of handling callbacks that return something, but yeah this might not work for promises. I've always had it...
Read more >
Rejection and How to Handle It (for Teens) - Kids Health
Feeling rejected is the opposite of feeling accepted. But being rejected (and we all will be at times) doesn't mean someone isn't liked,...
Read more >
Promise.reject() - JavaScript - MDN Web Docs
The Promise.reject() method returns a Promise object that is rejected with a given reason.
Read more >
JavaScript Promise Tutorial – How to Resolve or Reject ...
A Promise is a special JavaScript object. It produces a value after an asynchronous (aka, async) operation completes successfully, or an error ...
Read more >
Frequently Asked Questions - Jasmine Documentation
How can I configure a spy to return a rejected promise without triggering an ... However, that doesn't work with arrow functions, because...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found