假设我有以下序列:
vows.describe('Example').addBatch({
'An example' : {
topic: new Example(),
'with an async method' : function(example) {
example.asyncMethod(this.callback);
},
'will do some magic' : function(err, result) {
assert.equal(result.magical, true);
},
'and then we will be back on track' : function(example) {
assert.isTrue(example.backOnTrack);
}
}
}).run();
测试“然后我们将回到正轨
”是否可能符合之前的主题(示例
)?
编辑
vows.describe('Example').addBatch({
'An example' : {
topic: function(example){ // <- where example is a parent topic
example.asyncMethod(this.callback);
},
'callback after an async method will do some magic' : function(err, result) {
assert.equal(result.magical, true);
},
'and then we will be back on track' : function(example) {
assert.isTrue(example.backOnTrack);
}
}
}).run();
最佳答案
主题返回将发送到您所有誓言的主题。
在第一个誓言中,“使用异步方法”
this.callback
未定义,因为回调仅在主题中定义。在第二个誓言中,参数是 example
而不是 err, result
如果您想要进行任何异步测试,您需要为您的主题设置一个函数并使用 this.callback
或从主题返回一个 EventEmitter
。
编辑:
您遇到的问题是从誓言返回多个主题。这是不可能的。
最简单的解决方案是返回一个新主题,该主题是两个主题的数组。这感觉很黑客。
更好的解决方案是确保单独测试您的主题。基本上你的测试“副作用”已经成功发生。副作用不应该发生
关于node.js - 在 Vows.js 中,如何在经历异步回调后恢复到原始主题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7640946/