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

FeatureRequest: nested property matcher #1556

Closed
servel333 opened this issue Sep 11, 2017 · 3 comments
Closed

FeatureRequest: nested property matcher #1556

servel333 opened this issue Sep 11, 2017 · 3 comments

Comments

@servel333
Copy link
Contributor

Request to add this function signature: sinon.match.hasNested(keypath, expected)

where keypath functions like Lodash.get supporting "outer.inner" or "outer[inner]".

Turning this syntax into this syntax

sinon.match.has('outer', sinon.match.has('middle', sinon.match.has('inner', sinon.match.string)));
sinon.match.hasNested('outer.middle.inner', sinon.match.string);

Personally, I would prefer has supported nested keypaths, but that would probably break backwards compatibility. The implementation is simple if the addition of the lodash.get library is acceptable.

const get = require("lodash.get");

match.hasNested = createPropertyMatcher(function (actual, property) {
    return get(actual, property) !== undefined;
}, "hasNested");

@fatso83
Copy link
Contributor

fatso83 commented Sep 12, 2017

lodash.get is about 6k (2k gzipped), but we are not required to load in microseconds, so that should be fine. If you can supply a PR, that would be welcome.

@servel333
Copy link
Contributor Author

I would propose a custom implementation but I doubt it would have any benefits over a mature library like Lodash. I'll make a PR.

@mroderick
Copy link
Member

This was fixed with #1560

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

No branches or pull requests

3 participants