Unhandled rejection caught by vitest (I think I'm going mad) #1649
Replies: 3 comments 2 replies
-
|
Unhandled rejection means you are trowing an error outside of test, and Vitest couldn't track it. Also, I doubt you |
Beta Was this translation helpful? Give feedback.
-
|
So because I'm mocking method so that it will throw an error and it is defined outside of my test vitest will fail? What is the best way to approach mocking a library, so that it throws an error? It seems work, I was able to catch the correct error in my code and handle it as I wanted, the error also gets passed out as you can see in the expects().rejected (the hacky bit here is that I import just before calling vi.mock which stops it being hosited above the variables. |
Beta Was this translation helpful? Give feedback.
-
No, you have a code that runs after the test. This might happened because of not cleared timer, or not awaited promise. Try reproducing error on stackblitz. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there, I cannot seem to figure out why vitest seems to think it is handling an uncaught rejection. The idea of this test is that the setAttributesMock should throw an exception, I'm calling await expect(...).rejected etc and all the tests are passing. Any help would be greatly appreciated
My real code looks something like:
My test code looks something like this:
I know it probably isn't a false positive but there seems to be no way for me to ignore this warning / error. If I put a try catch around the whole test it still fails the tests command... does anyone know how I can disable this warning (as a last resort)
Beta Was this translation helpful? Give feedback.
All reactions