-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
rejects/resolves does not fail the test on non-promise value #5361
Comments
Good catch! This function should not be async: https://github.com/facebook/jest/blob/36c705bb1eac380e0926487bbe8b8db0aa2fa2e8/packages/expect/src/index.js#L159-L189 |
Hi, I'd like to take a look and submit a PR for this issue. |
Go for it! |
Added another test code in the description that's not as expected |
Note that the OP uses I still think we should give a proper synchronous error before switching into There is no way for jest to detect this scenario (help welcome in the lint plugin: jest-community/eslint-plugin-jest#54) |
Oh wow, what a bummer, totally forgot about it. |
It should be pretty easy using the eslint plugin. Help welcome 🙂 I don't think it's possible to detect in Jest itself as jest is runtime only - no static analysis (beyond what we do in the babel plugin) |
I see. Is there still something to do in this ticket then? |
Will close once #5364 is merged |
It's also reports false positives. I think there is something wrong the it('should fail', () => {
expect(Promise.resolve(false)).resolves.toBeTruthy();
}); This test case reports back as passed. However if I write it another way; it('should fail', async () => {
const res = await Promise.resolve(false);
expect(res).toBeTruthy();
}); This test case fails, as expected.
EDIT I do get the following in the console output
|
I think |
* Make `makeRejectMatcher` synchronizable (#5361) * Reorganize code using promise instaed of async/await * Update changelog * Move rejectedHandler onto then * Make `makeResolveMatcher` synchronizable * Update a snapshot * Update CHANGELOG.md * Update CHANGELOG.md
expect(foo): foo must be a promise when using rejects/resolves: jestjs/jest#5361
Here is what has worked for me.
|
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
expect(foo): foo must be a promise when using rejects/resolves: jestjs/jest#5361
Do you want to request a feature or report a bug?
Bug
What is the current behavior?
Passing a non-promise value to
rejects
orresolves
does not fail the testIf the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can
yarn install
andyarn test
.Test code
Also this one:
Output
What is the expected behavior?
Should fail the test
Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.
Node v9.3.0
Jest v22.1.2
Yarn v1.3.2
Mac OS X 10.12.6
The text was updated successfully, but these errors were encountered: