You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Promise.reject() expects a callback instead of an error (for testing .rejects) #4755
From the error message it seems the expect() wants a function instead of a promise, but expect(() => Promise.reject(new Error("octopus"))) also doesn't work (Expected promise\nReceived: [Function]).
After some more testing it seems it's Promise.reject() the one with a problem:
// Works (notice function in the reject):constrejecting=Promise.reject(()=>newError("octopus"));returnexpect(rejecting).rejects.toThrow("octopus");// Doesn't work (notice no function):constrejecting=Promise.reject(newError("octopus"));returnexpect(rejecting).rejects.toThrow("octopus");
However according to MDN, the correct syntax should be the one without the callback, not the one with the callback:
Promise.reject(newError('fail'))
Reacted by Bjön Limell, Eugene, Nico Mürdter, Julius Foitzik, Luke Childs, Luna, Nikita Karpukhin, Raphael Oliveira, Anderson Joseph, Christian Rishøj and 2 more
changed the title [-]expect().rejects doesn't work with Jest example[/-][+]Promise.rejects() expects a callback instead of an error (for testing `.rejects`)[/+]on Sep 10, 2023
changed the title [-]Promise.rejects() expects a callback instead of an error (for testing `.rejects`)[/-][+]Promise.reject() expects a callback instead of an error (for testing `.rejects`)[/+]on Sep 10, 2023
Activity
[-]expect().rejects doesn't work with Jest example[/-][+]Promise.rejects() expects a callback instead of an error (for testing `.rejects`)[/+][-]Promise.rejects() expects a callback instead of an error (for testing `.rejects`)[/-][+]Promise.reject() expects a callback instead of an error (for testing `.rejects`)[/+]franciscop commentedon Sep 15, 2023
Confirmed as still happening in Bun 1.0.2
nektro commentedon May 24, 2024
does this still reproduce for you? it appears to be working on my end in Bun 1.1.9 (you may need to run
bun upgrade)franciscop commentedon May 25, 2024
I can confirm this works now! A rejected promise works properly and as expected in JS:
And the default example I put above works. Thanks for fixing this!