Vows.js:访问从内部主题内部的外部主题返回的参数

时间:2011-09-01 07:02:02

标签: javascript node.js bdd vows

我想知道是否有任何方法可以从内部主题的测试中获取外部主题的返回值。如果这令人困惑,这是一个例子:

"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?
      }
    ...
  }
  ...

1 个答案:

答案 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?
  }
...

基本上,您可以在任何子主题中获得以前的主题数据。然后,您需要手动将其传递给誓言。是的,这是一种痛苦。