assert: [(not)include] throw on incompatible haystack. Closes #142

This commit is contained in:
Jake Luer 2013-04-29 19:30:51 -04:00
parent 8f8d7425a5
commit 019bb07637
2 changed files with 18 additions and 0 deletions

View file

@ -645,6 +645,11 @@ module.exports = function (chai, util) {
obj.to.include(inc);
} else if ('string' === typeof exp) {
obj.to.contain.string(inc);
} else {
throw new chai.AssertionError({
message: 'expected an array or string'
, stackStartFunction: assert.include
});
}
};
@ -671,6 +676,11 @@ module.exports = function (chai, util) {
obj.to.not.include(inc);
} else if ('string' === typeof exp) {
obj.to.not.contain.string(inc);
} else {
throw new chai.AssertionError({
message: 'expected an array or string'
, stackStartFunction: assert.include
});
}
};

View file

@ -357,6 +357,10 @@ suite('assert', function () {
err(function () {
assert.include('foobar', 'baz');
}, "expected \'foobar\' to contain \'baz\'");
err(function () {
assert.include(undefined, 'bar');
}, "expected an array or string");
});
test('notInclude', function () {
@ -366,6 +370,10 @@ suite('assert', function () {
err(function () {
assert.notInclude('foobar', 'bar');
}, "expected \'foobar\' to not contain \'bar\'");
err(function () {
assert.notInclude(undefined, 'bar');
}, "expected an array or string");
});
test('lengthOf', function() {