-
Notifications
You must be signed in to change notification settings - Fork 29
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
Add assertion to be contained by
#255
Comments
|
@bruderstein I'm obviously not a native English speaker :-) So let's just use `to be contained in'. |
Yay! I've been lacking a |
Here's my hacked together subset-check: Feel free to pifler as needed :) expect.addAssertion('<any> to be a subset of <array>', function (expect, has, wantAtLeast) {
if (!Array.isArray(has)) { has = [has]; }
// See what's common between both sets
var intersection = _.intersection(has, wantAtLeast);
// If all input is in the common set, we're OK
if (intersection.length !== has.length) {
expect.fail({
message: function (output) {
return 'Expected', has, 'to be in', wantAtLeast;
},
diff: function (output, diff, inspect, equal) {
return diff(has.sort(), intersection.sort());
}
});
}
}); Generally, I've been missing some set theory in here; I'm currently writing a lot of API stubs where I have to check that returned data has one of some known values in certain properties. Come to think of it, being able to do expect(resp, 'to satisfy', {
platform: expect.it('to be one of', ['ios', 'android', 'kindle']),
...
}); |
@msiebuhr That looks very useful! http://unexpected.js.org/unexpected-set/ already supports |
You're welcome! I'm not using sets (hello, Node 0.12.x) and I generally avoid using |
As for the last snippet, this works today: expect(resp, 'to satisfy', {
platform: expect.it('to equal', 'ios').or('to equal', 'android').or('to equal', 'kindle')
}); |
The scope of unexpected-set includes exploring assertions with set semantics. It includes a
Really? What sort of thing have you run into? |
In unexpected-moment, In general, I don't trust that I other people on the project can figure out the semantics of Having
A bit more stutter, but I guess that can do for now. Also - it does seem one can build quite complex assertions with chains of |
The only documentation of expect.it is in to satisfy, we should probably try to explain the precedence a little bit better - it is only the indentation that gives a clue. The same indentation is also used when outputting expect.it in an error message.
This is horrible - you should just make a custom assertion if it is not provided by a plugin. I don't want set operations in core, I think it belongs in unexpected-set. But strictly speaking it is also wrong to use arrays as sets, maybe another terminology could be used:
The last assertion already exists but it is unfortunately varargs :-( |
I always implement this assertion as it is pretty useful:
The text was updated successfully, but these errors were encountered: