Tag:

如果在抛出任何错误的时候如何在promise中做出断言,不会冒出来呢?

与摩卡运行这个结果超时,而不是让摩卡赶上错误,所以它可能会立即失败.. var when = require('when'); var should = require('should'); describe('', function() { it('', function(done) { var d = when.defer(); d.resolve(); d.promise.then(function() { true.should.be.false; false.should.be.true; throw new Error('Promise'); done(); }); }); }); http://runnable.com/me/U7VmuQurokZCvomD 是否有另外一种方式在诺言中作出断言,如果失败,他们会被摩卡抓住,导致立即失败? 根据柴的build议,我研究了它,似乎我必须有一个直接访问的承诺对象,对不对? 问题是,我没有直接使用诺言。如果我简化,我的坏,但这将是一个更接近现实的例子 function core_library_function(callback){ do_something_async(function which_returns_a(promise){ promise.then(function(){ callback(thing); }); }); } describe('', function() { it('', function(done) { core_library_function(function(thing){ … done(); }); }); […]