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

Assertion Request: deepMatch() #643

Closed
numbnut opened this issue Mar 17, 2016 · 2 comments
Closed

Assertion Request: deepMatch() #643

numbnut opened this issue Mar 17, 2016 · 2 comments

Comments

@numbnut
Copy link

numbnut commented Mar 17, 2016

I can't find anything regarding a deep or nested match functionality. What I'm looking for is an assertion function which matches two objects based on regular expressions.

var result = {a: "contains foo", b: "contains bar"}
var expected = {a: /foo/, b: /bar/}
assert.deepMatch(result, expected)

This would be a combination of a deepEqual() and the match() assertion functions. This could be useful, in situations where an object contains unpredictable data following a pattern. In my case this is an id set by the database.

Do I miss something? I can't figure out a way to achieve this behavior without a workaround.

Thanks in advance

@lucasfcosta
Copy link
Member

Hi @numbnut, I'm currently not sure if this is common enough for us to cover it.
But well, we can discuss about this. It would be great to hear other people's opinions before giving a definitive answer to it.

For now you can use match individually to test each one of the object's properties, after all you are already kind of doing this when you create your expected object, so (in my opinion) there's not a big difference between creating an object with multiple RegExps and using multiple assertions with the same RegExps you put on your object.

Thanks for your feedback and please feel free to share further thoughts on this and ask any questions you would like to.

@keithamus
Copy link
Member

Hey @numbnut - thanks for the issue.

As @lucasfcosta says - I'm not sure if this is a common enough scenario for us to look at.

We have had similar issue before though, for example #426. We've also discussed the idea of having an api for making assertions on deep properties, for example #97 and #324. I've raised a new issue; #644 which I think we should focus on, and it would help you with the issues you're having.

I'll close this in favour of #644 for now, but let me know what you think - either in #644 or below 😄

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