-
Notifications
You must be signed in to change notification settings - Fork 142
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
allow using matchers inside contains #317
Conversation
Very cool! I think @Schoonology requested this a while back |
I just added a couple additional checks to this branch, and found one issue: that this does not apply to arrays as one would expect. Here's the failing test I added: this.matches(td.matchers.contains(td.matchers.isA(Number)), ['a', 3, 'b']) === true I'll take a look to see if this is a trivial addition to the function you changed |
I didn't have much luck making this behave consistently for arrays (the complexity of the private function is now at a point where it seems a single recursive function would be preferable to two half-functions given that |
Thanks for the feedback! I was able to make the tests pass with a bit extra complexity.. We could possibly split those in separate sub functions. I tried to break this but couldn't. My examples: const brewNew = td.function();
brewNew(['sdf', {test: 'abc'}, 4, {testNew: 'sdf'}, {testAlso: {stringy: 'string', number: 4}}]);
td.verify(
brewNew(
td.matchers.contains(
{test: 'abc'},
td.matchers.isA(String),
td.matchers.isA(Number),
{testNew: td.matchers.isA(String)},
{
testAlso: td.matchers.contains({
stringy: 'string', number: td.matchers.isA(Number)
}
)
}
)
)
);
const newer = td.function();
newer({
lol: {
deep:
[{ad: ['wer', {evenDeeper: [function () {}, 4]}, 3]}, 2]
},
other: 'stuff'
});
td.verify(newer(td.matchers.contains({
lol: {
deep: [{
ad: ['wer', {evenDeeper: td.matchers.contains(td.matchers.isA(Number), 4)}]
}]
}
}))); |
I just realized that if I simplify the code more, to:
(removing the && !_.isArray(containing) check in the second line and wrapping the containing as an array)
So I've added a test to cover a more complex example like this one. I switched from a function inside the array to an object - I couldn't figure out how to make something like that in coffeescript, and didn't particularly fancy learning that ;-) |
Hey, thanks for merging @searls ! The recent changes I talked about were here: Not sure if you decided it was making thet initially function too complex, or assumed my changes were here :-) |
I iterated on this a bit more today and was able to simplify things quite a bit further. Just cut a release. Thanks for this contribution!! Landed in 3.3.0. |
Right, I see now. Much cleaner - great work :-) Thanks for this fantastic library - it, and it's docs, changed the way I think about testing. |
This allows us to do things like:
Before, the tests I added were failing (basically, you weren't able to mix matcher.contains with other matchers (including another matcher.contains as showed above)