Repository: chaijs/chai (JavaScript)

Issue:
Obj is oneOf array of objects
Hi ! :)

I would to test if an object if one of entries from an array containing objects.
It's something like: `expect({}).to.deep.oneOf([{}, {}, {}])`

But I got this error: `AssertionError: expected { Object (type, sender, ...) } to be one of [ Array(3) ]`

With more details, this is the test with the object and the array:

```
expect({
  "type": "text",
  "sender": "bot",
  "user": "USER_TEST",
  "payload": {
    "value": "Lorem ipsum"
  }
}).to.deep.oneOf([
  {
    "type": "text",
    "sender": "bot",
    "user": "USER_TEST",
    "payload": {
      "value": "Dolor sit amet"
    }
  },
  {
    "type": "text",
    "sender": "bot",
    "user": "USER_TEST",
    "payload": {
      "value": "Lorem ipsum"
    }
  },
  {
    "type": "text",
    "sender": "bot",
    "user": "USER_TEST",
    "payload": {
      "value": "Consectetur adipiscing elit"
    }
  }
])
```

How can I do this kind of test ?


Discussion:
Having the same issue; my example can be simplified straight down to this:
```javascript
expect([]).to.be.deep.oneOf([[], ''])
```

![image](https://user-images.githubusercontent.com/1940488/65474544-8ac81900-debf-11e9-8209-30dd506ffbad.png)


Looks like `oneOf` doesn't check for `deep`?
Is there any update on this?



Patch:
diff --git a/lib/chai/core/assertions.js b/lib/chai/core/assertions.js
index 5c071fb72..c6f97fe0a 100644
--- a/lib/chai/core/assertions.js
+++ b/lib/chai/core/assertions.js
@@ -3150,7 +3150,8 @@ module.exports = function (chai, _) {
     var expected = flag(this, 'object')
       , flagMsg = flag(this, 'message')
       , ssfi = flag(this, 'ssfi')
-      , contains = flag(this, 'contains');
+      , contains = flag(this, 'contains')
+      , isDeep = flag(this, 'deep');
     new Assertion(list, flagMsg, ssfi, true).to.be.an('array');
 
     if (contains) {
@@ -3162,13 +3163,23 @@ module.exports = function (chai, _) {
         , 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
-      );
+      if (isDeep) {
+        this.assert(
+          list.some(possibility => _.eql(expected, possibility))
+          , 'expected #{this} to deeply equal one of #{exp}'
+          , 'expected #{this} to deeply equal 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
+        );
+      }
     }
   }
 


Test patch:
diff --git a/test/expect.js b/test/expect.js
index c3ce110e2..d1d1fe9e1 100644
--- a/test/expect.js
+++ b/test/expect.js
@@ -3308,6 +3308,7 @@ describe('expect', function () {
     expect([3, [4]]).to.not.be.oneOf([1, 2, [3, 4]]);
     var threeFour = [3, [4]];
     expect(threeFour).to.be.oneOf([1, 2, threeFour]);
+    expect([]).to.be.deep.oneOf([[], '']);
 
     expect([1, 2]).to.contain.oneOf([4,2,5]);
     expect([3, 4]).to.not.contain.oneOf([2,1,5]);