-
-
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
toEqual ignores keys with undefined properties #711
Comments
@jamedranoa yes, I plan on eventually removing this check. Unfortunately we have a shitload of tests at FB that depend on this behavior. My goal is to unfork jasmine eventually though, it'll happen in the next few months. |
Cool thank you! 👍 |
@cpojer Are there still plans to remove this? |
@scsper we still have plans, but there's still too many FB tests that depend on this behavior, so it's not going to happen soon :/ |
Hey guys, what about adding a feature switch for us open source users to use |
Is there a workaround for this? |
@cpojer any updates on this issue? I ran into it recently and noticed this issue has gone stale. |
You can create your own matcher using lodash.toEqual if you want |
@SimenB For now I have a couple workarounds (e.g. using |
Hmmm... the issue says it ignores Wish there was a way to toggle the behavior. In my case I want it to ignore undefined as JSON.stringify will strip undefined properties anyway (so I don't care). |
@lukescott |
Is anyone concerned with this? I got a bug today because of this issue. |
This is sorta fixed, we have EDIT: based on this comment, I'll call this issue fixed:
Slightly a footgun that's it's not the default, but legacy. If you want to enforce usage in your code base, you can use jest-community/eslint-plugin-jest#134, which can autofix your code |
- split the implem into merge(target, ...sources) and _merge(target, source), I think it's more simple this way. - I reorganized some of the conditions - I mostly kept the description and the test suite as I think they are still relevant. Only a minor change to note in the tests: > changed all of them to use expect().toStrictEqual instead of .toEqual (see: jestjs/jest#711)
cf. jestjs/jest#711 `undefined` values being critical to in assessing merge behaviour this is necessary
* fix(merge): use .toStrictEqual instead of .toEqual in tests cf. jestjs/jest#711 `undefined` values being critical to in assessing merge behaviour this is necessary * fix(merge): specify description add meaning of array-like * fix(merge): change implementation - split the implem into merge(target, ...sources) and _merge(target, source), I think it's more simple this way. - I reorganized some of the conditions The description and the test suit should not change. Implementation has changed but behaviour and limitation is the same (Note that the lodash inspired test suite for merge should be passing). * fix: extra-space Co-Authored-By: Yannick Croissant <[email protected]> * fix: rename isObjectOrArray to isObjectOrArrayOrFunction
* fix(merge): use .toStrictEqual instead of .toEqual in tests cf. jestjs/jest#711 `undefined` values being critical to in assessing merge behaviour this is necessary * fix(merge): specify description add meaning of array-like * fix(merge): change implementation - split the implem into merge(target, ...sources) and _merge(target, source), I think it's more simple this way. - I reorganized some of the conditions The description and the test suit should not change. Implementation has changed but behaviour and limitation is the same (Note that the lodash inspired test suite for merge should be passing). * fix: extra-space Co-Authored-By: Yannick Croissant <[email protected]> * fix: rename isObjectOrArray to isObjectOrArrayOrFunction
It might help if the docs for toEqual mentioned the ways in which it differs from toStrictEqual instead of you having to discover toStrictEqual on your own. |
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. |
If a property is undefined, Jest appears to ignore it when calling .toEqual().
import _ from "lodash"; describe("test", () => { it("returns an object with the correct nodes", () => { let a = {"key1": undefined, "key2": "a"}; let b = {"key2": "a"}; expect(a).toEqual(b); expect(_.isEqual(a, b)).toBeFalsy(); }); });
This simple test will pass. As you can see by adding lodash, it should be false.
My output:
Using Jest CLI v0.8.2, jasmine1
Running 1 test suite...
PASS processors\hockey__tests__\events.js (0.573s)
1 test passed (1 total in 1 test suite, run time 1.076s)
----------|----------|----------|----------|----------|----------------|
File | % Stmts | % Branch | % Funcs | % Lines |Uncovered Lines |
----------|----------|----------|----------|----------|----------------|
----------|----------|----------|----------|----------|----------------|
All files | 100 | 100 | 100 | 100 | |
----------|----------|----------|----------|----------|----------------|
The text was updated successfully, but these errors were encountered: