How to test promises with Mocha
问题 I'm using Mocha to test an asynchronous function that returns a promise. What's the best way to test that the promise resolves to the correct value? 回答1: Mocha has built-in Promise support as of version 1.18.0 (March 2014). You can return a promise from a test case, and Mocha will wait for it: it('does something asynchronous', function() { // note: no `done` argument return getSomePromise().then(function(value) { expect(value).to.equal('foo'); }); }); Don't forget the return keyword on the