@@ -3118,6 +3118,14 @@ module.exports = function (chai, _) {
3118
3118
* expect(1).to.equal(1); // Recommended
3119
3119
* expect(1).to.not.be.oneOf([2, 3, 4]); // Not recommended
3120
3120
*
3121
+ * It can also be chained with `.contain` or `.include`, which will work with
3122
+ * both arrays and strings:
3123
+ *
3124
+ * expect('Today is sunny').to.contain.oneOf(['sunny', 'cloudy'])
3125
+ * expect('Today is rainy').to.not.contain.oneOf(['sunny', 'cloudy'])
3126
+ * expect([1,2,3]).to.contain.oneOf([3,4,5])
3127
+ * expect([1,2,3]).to.not.contain.oneOf([4,5,6])
3128
+ *
3121
3129
* `.oneOf` accepts an optional `msg` argument which is a custom error message
3122
3130
* to show when the assertion fails. The message can also be given as the
3123
3131
* second argument to `expect`.
@@ -3136,16 +3144,27 @@ module.exports = function (chai, _) {
3136
3144
if ( msg ) flag ( this , 'message' , msg ) ;
3137
3145
var expected = flag ( this , 'object' )
3138
3146
, flagMsg = flag ( this , 'message' )
3139
- , ssfi = flag ( this , 'ssfi' ) ;
3147
+ , ssfi = flag ( this , 'ssfi' )
3148
+ , contains = flag ( this , 'contains' ) ;
3140
3149
new Assertion ( list , flagMsg , ssfi , true ) . to . be . an ( 'array' ) ;
3141
3150
3142
- this . assert (
3151
+ if ( contains ) {
3152
+ this . assert (
3153
+ list . some ( possibility => expected . indexOf ( possibility ) > - 1 )
3154
+ , 'expected #{this} to contain one of #{exp}'
3155
+ , 'expected #{this} to not contain one of #{exp}'
3156
+ , list
3157
+ , expected
3158
+ ) ;
3159
+ } else {
3160
+ this . assert (
3143
3161
list . indexOf ( expected ) > - 1
3144
- , 'expected #{this} to be one of #{exp}'
3145
- , 'expected #{this} to not be one of #{exp}'
3146
- , list
3147
- , expected
3148
- ) ;
3162
+ , 'expected #{this} to be one of #{exp}'
3163
+ , 'expected #{this} to not be one of #{exp}'
3164
+ , list
3165
+ , expected
3166
+ ) ;
3167
+ }
3149
3168
}
3150
3169
3151
3170
Assertion . addMethod ( 'oneOf' , oneOf ) ;
0 commit comments