-
Notifications
You must be signed in to change notification settings - Fork 207
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
Value be Something OR SomethingElse #138
Comments
I know I can use a ternary to select the correct value before giving it to expect, but that seems sloppy to me if expect supports this already. |
What about expect(value === 1 || value === 'abcd').to.be(true); ? |
In my tests I have currently written something like that, but the logical operator was in the expect(actualValue).to.be(testValue === 1 || testValue === 'abcd'); This works but it was ugly. I was looking for something better. |
I usually declare variables for each such option, especially when I have >= 3 of those. So for example you could write:
|
|
Another variant: expect.Assertion.prototype.stringOrArrayOfStrings = function() {
var ok;
if (typeof this.obj == 'string') {
ok = true;
} else if (this.obj instanceof Array) {
ok = true;
for(var i = 0; i < this.obj.length; ++i) {
if (typeof this.obj[i] != 'string') {
ok = false;
break;
}
}
} else {
ok = false;
}
this.assert(ok, function() {
return 'expected ' + expect.stringify(this.obj) + ' to be a string or an array of strings';
}, function() {
return 'expected ' + expect.stringify(this.obj) + ' to not be a string or an array of strings';
});
};
expect(config.session.secret).to.be.stringOrArrayOfStrings(); |
I'm trying to test that a value is one value or another. In either case it's considered passing but I have not been able to figure out how to test for this.
Does expect.js support this sort of assertion and if not how should I go about testing for it?
The text was updated successfully, but these errors were encountered: