【问题标题】:Vows.js: Accessing parameters returned from outer topics inside inner topicsVows.js:在内部主题中访问从外部主题返回的参数
【发布时间】:2011-09-01 07:02:01
【问题描述】:

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

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

【问题讨论】:

    标签: javascript node.js bdd vows


    【解决方案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?
      }
    ...
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-09-08
      • 2018-05-13
      • 2017-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-09
      • 2016-08-04
      相关资源
      最近更新 更多