-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ava's test.throws accepts Promise value #27
Comments
Thanks for reporting. I overlooked that missing feature... We cannot reliably detect if an argument is a promise, so I'm not sure what the right solution is. After the transformation, which error do you get from Jest? |
@cpojer any suggestions? |
nothing yet beyond the last few suggestions in the issue mentioned above. |
@ahutchings seems like this is fixed in jestjs/jest#3068 ... Does Jest>20 work for you? |
@ahutchings did you have time to test newest version of Jest? Thanks. |
I just tried this with jest@20, and there is at least one case that does not work. Input: import test from 'ava';
test('promise throws', async t => {
const error = new Error('Some error');
const promise = Promise.reject(error);
const err = await t.throws(promise);
t.is(err.message, 'Some error');
}); Output: test('promise throws', async () => {
const error = new Error('Some error');
const promise = Promise.reject(error);
const err = await expect(promise).toThrow();
expect(err.message).toBe('Some error');
}); Console Output: > [email protected] test /Users/ahutchin/Projects/jest-codemods-27
> jest
(node:70794) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Some error
(node:70794) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
FAIL ./test.js
● promise throws
expect(function).toThrow(undefined)
Received value must be a function, but instead "object" was found
at Object.<anonymous>.test (test.js:5:37)
at Promise (<anonymous>)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
✕ promise throws (4ms) |
Thanks! |
I had the same issue, except I was dependent on the return value of What I did was a manual find-replace
to every file, followed by
|
When Ava's
test.throws
is used with a Promise value, it cannot be transformed directly to a Jest.toThrowError
call, since the latter does not support Promise values.Any ideas on what can be done here? jestjs/jest#1377 looks like it might be related.
The text was updated successfully, but these errors were encountered: