-
-
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
feature request: Ability/option to disable dot notation for deep equality when using .toHaveProperty #3873
Comments
Since this matcher is already kind of special, maybe it's worth to add a third argument? expect(flattenedObject).toHaveProperty('nested.key', 'value', {dot: false}); |
Is this still a feature that is wanted (since it has Discussion label) ? It seems not too difficult to add this feature, and I would like to make a PR for it. 😄 |
I'm for that change. It doesn't break the API and looks like will make your life easier ;) |
One issue I found already is that the current API also supports But since the options argument has to be the current non-existing third argument, then we can't have that API for when options would be passed... |
this should work? expect(flattenedObject).toHaveProperty('nested.key', expect.any(), {dot: false}); |
i was thinking about implementing a support for array arguments, because we store a lot of paths in array constants. like this: expect({a: {b: {c: 1}}}).toHaveProperty(['a', 'b', 'c'], 1); your case will look like: expect({'a.b.c': 1}).toHaveProperty(['a.b.c'], 1); would that work? |
it'll also enable array indexes in paths without crazy expect([{a: {b: 1}, null]).toHaveProperty([0, 'a', 'b'], 1); |
Ran into this while testing a I like the idea of using arrays (as @aaronabramov mentioned) instead of dot-paths. FWIW, this is the API that ImmutableJS uses for the One other thought: any reason not to have the API try both options? When a string with a |
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. |
I am flattening (using flat) deeply nested objects and performing business logic on it based on the flattened keys/values. In example:
I would like to test that a key is on my object and has a particular value after being flattened, however because
.toHaveProperty
uses dot notation for checking deeply nested references I am unable to do so.Example:
Fails with:
The work around for this is:
Example/testable repository: https://github.com/dmmulroy/jest-toHaveProperty-feature-request
The text was updated successfully, but these errors were encountered: