mirror of
https://github.com/chaijs/chai
synced 2024-11-14 15:57:10 +00:00
feat(oneOf): expect(value).to.contain.oneOf([])
This commit is contained in:
parent
5930c0112f
commit
7eaf684b1a
1 changed files with 18 additions and 7 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue