title: Testing Promise-chains with Mocha
body: <p>I've got the following style of function (using bluebird promises under Node.JS):</p>
  
  <pre><code>module.exports = {
      somefunc: Promise.method(function somefunc(v) {
          if (v.data === undefined)
              throw new Error("Expecting data");
  
          v.process_data = "xxx";
  
          return module.exports.someother1(v)
            .then(module.exports.someother2)
            .then(module.exports.someother3)
            .then(module.exports.someother4)
            .then(module.exports.someother5)
            .then(module.exports.someother6);
      }),
  });
  </code></pre>
  
  <p>which I'm trying to test (using mocha, sinon, assert):</p>
  
  <pre><code>// our test subject
  something = require('../lib/something');
  
  describe('lib: something', function() {
      describe('somefunc', function() {
          it("should return a Error when called without data", function(done) {
              goterror = false;
              otherexception = false;
              something.somefunc({})
              .catch(function(expectedexception) {
                  try {
                      assert.equal(expectedexception.message, 'Expecting data');
                  } catch (unexpectedexception) {
                      otherexception = unexpectedexception;
                  }
                  goterror = true;
              })
              .finally(function(){
                  if (otherexception)
                      throw otherexception;
  
                   assert(goterror);
                   done();
              });
          });
  });
  </code></pre>
  
  <p>All of which works as such, but feels convoluted for one.</p>
  
  <p>My MAIN problem is testing the Promises-chain (and order) in the function. I've tried several things (faking an object with a then method, which didn't work; mocking it like crazy, etc); but there seems to be something I'm not seeing, and I don't seem to be getting the mocha- or sinon- documentations in this regard.</p>
  
  <p>Anybody got any pointers?</p>
  
  <p>Thanks</p>
  
  <p>count</p>