From 7eaf684b1a8c2e081fa01d91e0655ba988849301 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Oliva?= Date: Wed, 26 Jun 2019 23:18:10 +0200 Subject: [PATCH] feat(oneOf): expect(value).to.contain.oneOf([]) --- lib/chai/core/assertions.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) 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);