feat(oneOf): expect(value).to.contain.oneOf([])

This commit is contained in:
Víctor Oliva 2019-06-26 23:18:10 +02:00
parent 5930c0112f
commit 7eaf684b1a

View file

@ -3135,16 +3135,27 @@ module.exports = function (chai, _) {
if (msg) flag(this, 'message', msg);
var expected = flag(this, 'object')
, flagMsg = flag(this, 'message')
, ssfi = flag(this, 'ssfi');
, ssfi = flag(this, 'ssfi')
, contains = flag(this, 'contains');
new Assertion(list, flagMsg, ssfi, true).to.be.an('array');
this.assert(
if (contains) {
this.assert(
list.some(possibility => expected.indexOf(possibility) > -1)
, 'expected #{this} to contain one of #{exp}'
, 'expected #{this} to not contain one of #{exp}'
, list
, expected
);
} else {
this.assert(
list.indexOf(expected) > -1
, 'expected #{this} to be one of #{exp}'
, 'expected #{this} to not be one of #{exp}'
, list
, expected
);
, 'expected #{this} to be one of #{exp}'
, 'expected #{this} to not be one of #{exp}'
, list
, expected
);
}
}
Assertion.addMethod('oneOf', oneOf);