我想知道是否有任何方法可以从内部主题的测试中获取外部主题的返回值。如果这令人困惑,这是一个例子:
"build.css" : {
topic : function(file) {
fs.readFile(fixtures + "/public/build.css", "utf8", this.callback);
},
'exists' : function(err, build) {
assert.isNull(err); // This is fine..
},
{
'should contain' : {
topic : function() {
return "wahoo";
},
'some cool css' : function(wahooString, err, build) {
// Where did build go? Can I still access it from this scope?
}
...
}
...
答案 0 :(得分:1)
伪代码:
'should contain' : {
topic : function(err, build) {
this.callback(err, build, "wahoo");
return undefined;
},
'some cool css' : function(err, build, wahooString) {
// Where did build go? Can I still access it from this scope?
}
...
基本上,您可以在任何子主题中获得以前的主题数据。然后,您需要手动将其传递给誓言。是的,这是一种痛苦。