【发布时间】:2014-08-24 19:21:21
【问题描述】:
使用 mocha 运行它会导致超时,而不是让 mocha 捕获错误,因此它可能会立即失败..
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
是否有另一种方法可以在 Promise 中进行断言,这样当它们失败时,它们会被 mocha 捕获,导致它立即失败?
根据 chai 的建议,我研究了一下,似乎我必须直接访问 promise 对象,对吧?问题是我没有直接使用promise .. 如果我简化了我的错,但这将是一个更接近现实的例子
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();
}); }); });
所以我真的无法直接控制 Promise,它被抽象得很远。
【问题讨论】:
-
按承诺考虑柴
标签: node.js promise mocha.js throw