Skip to content

Commit

Permalink
feat(oneOf): expect(value).to.contain.oneOf([])
Browse files Browse the repository at this point in the history
  • Loading branch information
voliva committed Jun 26, 2019
1 parent 5930c01 commit 7eaf684
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions lib/chai/core/assertions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7eaf684

Please sign in to comment.