假设我有以下顺序:
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();测试"and then we will be back on track“是否可以使用以前的主题(Example)?
编辑
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();发布于 2011-10-04 09:42:02
主题返回将发送给所有誓言的主题。
在第一个誓言中,"with an async method" this.callback未定义,因为回调只在主题中定义。在第二个誓言中,参数是example而不是err, result
如果您想要进行任何异步测试,您需要为主题设置一个函数并使用this.callback或从主题返回一个EventEmitter。
编辑:
您的问题是从誓言中返回多个主题。这是不可能的
最简单的解决方案是返回一个新主题,即由两个主题组成的数组。这感觉很烦人。
更好的解决方案是确保孤立地测试主题。基本上你的测试“副作用”已经成功发生了。副作用永远不会发生。
发布于 2011-10-04 02:44:53
据我所知,topic无论使用简单的topic: something还是topic: function(...语法,只执行一次。在第二个示例中,当誓言按顺序执行时,您将处理修改后的example。
我会采取简单但有点烦人的方法,将两个测试分解成子上下文,并有两个topic: new Example()实例。
https://stackoverflow.com/questions/7640946
复制相似问题