Skip to content
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: wildcard in nested assertion #1167

Closed
Janpot opened this issue Jun 14, 2018 · 3 comments
Closed

Feature request: wildcard in nested assertion #1167

Janpot opened this issue Jun 14, 2018 · 3 comments

Comments

@Janpot
Copy link

Janpot commented Jun 14, 2018

I quite often find myself in need to assert for nested properties where the path isn't always fully known. Most of the times when I want to check whether a nested array contains an object with a certain property. Would it be possible to allow wildcards in the path?

// maybe something like
assert.nestedPropertyVal(obj, 'foo[?].bar', 'baz');
// or
assert.nestedPropertyVal(obj, 'foo[*].bar', 'baz');
// or maybe even with a regex
assert.nestedPropertyVal(obj, 'foo[/.*/].bar', 'baz');
@demurgos
Copy link

demurgos commented Jun 16, 2018

Not sure if the feature should be included or not in chai core, but if you decide to go with it I'd prefer a less ambiguous API:

assert.nestedPropertyVal(obj, [/foo.*/s, 'bar'], 'baz');

Instead of requiring some special parsing, just materialize the property path with an array, use strings for constants and regexes for dynamic parts. This does not support "any-depth" matches (such as git's wildstar **) but you could add a symbol for it or just write you own chai plugin using something based on minimatch for this kind of advanced feature.

@Janpot
Copy link
Author

Janpot commented Jun 17, 2018

I'd prefer a less ambiguous API

I agree on that point. But it already supports that kind of path notation, so special parsing is already happening.

@keithamus
Copy link
Member

Hey @Janpot thanks for the issue. Thanks for the extra comments @demurgos.

We'll look into adding this for Chai 5. We've added this to our Roadmap to investigate further. We'll be releasing chai 5 soon, but for now I'll close this issue because it is tracked on our roadmap.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants