-
-
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
Regression regarding not.toHaveProperty() and non-object input #7942
Comments
Confirmed. See #7686 which fixed another regression with unguarded The only restriction (by design) on received value of While testing examples of primitive types in Jest 23.6 especially falsey values, I found (again) an unintended matcher error for |
Thanks for taking a look.
For One example. (In a pre-check) you want to test that it's not an "error response" (an object with an function expectNoErrorResponse(resp) {
expect(resp).not.toHaveProperty("isError", true);
}
//
const response = fetchSomeResponse();
expectNoErrorResponse(response);
expect(response).toBe(null); Just an idea. I'm not completely against throwing on |
|
It is good to discuss decisions whether matcher fails or throws an error for received value. For example, we fixed a mistake in #7107 where decision to throw:
When a test fails, the report provides relevant information so tester can decide:
If test asserts that a property does not exist:
What do y’all think? |
Hi @pedrottimark, first I want to thank you for really thinking about what's the best behavior from the viewpoint of an API consumer (a test writer and reader). BTW, I think the symmetry argument from above is not that important (especially because the It's a fact that formulating negative assertions is often very fragile (i.e. can lead to false positive assertions due to badly formulated predicates, later test or SUT refactorings, ...). One practice I've learned is to combine negative assertions always with positive assertions (or if this isn't possible with counter-assertions in the arrange phase, or in another counter-example test). So. From a pure (non test related) API perspective, I personally would not throw for nullish "actual" input because this would be the exact negation of the behavior of the positive "toHaveProperty" assertion. (Of course for any invalid "expected" input it should throw; that's your point 1). => It's a trade-off. Overall I'm tended to go for the more conservative way and throw for nullish also in the |
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. |
💥 Regression Report
.not.toHaveProperty()
doesn't work with non-object "actual" values, instead it throwsTypeError: Cannot use 'in' operator
.Last working version
Worked up to version: 23.6.0
Stopped working in version: 24.1.0
To Reproduce
Expected behavior
No failure in the snippet above.
The text was updated successfully, but these errors were encountered: