title: Weird failed assertion with mocha/chai and ES6 Promise
body: <p>I faced a strange behavior with ES6 Promise and some mocha/chai tests.
  Considering the following <code>foo()</code> function that returns a promise, I want to test two things:  </p>
  
  <ul>
  <li>it returns a promise (and so, an object)  </li>
  <li>it throws an exception (and so, an object) on failure.</li>
  </ul>
  
  <p>Problem is, following test <code>expect(..).to.be.an('object')</code> fails in both case, but the type <strong>is</strong> <code>object</code> (checked with <code>typeof</code>).</p>
  
  <p>Here is my code:</p>
  
  <pre><code>var chai = require('chai');
  var expect = chai.expect;
  
  var foo = function (a, b) {
    return new Promise(function(resolve, reject) {
      if (a &lt; b) {
        resolve();
      }
      else {
        throw new Error('failed');
      }
    });
  }
  
  describe('foo function', function () {
    it('should return a promise', function () {
      var call = foo();
  
      //typeof call: object
      expect(call).to.be.defined; //pass
      expect(call).to.be.an('object'); //fail
      expect(call.then).to.be.a('function'); //pass
    });
  
    it('should throw an exception on failure', function () {
      return foo().catch(function (e) {
  
        //typeof e: object
        expect(e).to.be.defined; //pass
        expect(e).to.be.an('object'); //fail
      });
    })
  });
  </code></pre>
  
  <p>Do you have any clue to explain this?</p>
  
  <p>If it can helps, here is the result of the mocha call <code>mocha test.js</code></p>
  
  <pre><code>foo function
    1) should return a promise
    2) should throw an exception on failure
  
  
  0 passing (20ms)
  2 failing
  
  1) foo function should return a promise:
     AssertionError: expected {} to be an object
      at Context.&lt;anonymous&gt; (test.js:34:24)
  
  2) foo function should throw an exception on failure:
     AssertionError: expected [Error: failed] to be an object
      at test.js:42:23
  </code></pre>