diff --git a/lib/chai/core/assertions.js b/lib/chai/core/assertions.js index cabcf622f..d9daff0d5 100644 --- a/lib/chai/core/assertions.js +++ b/lib/chai/core/assertions.js @@ -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);