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

发布于 2024-12-02 13:31:21 字数 530 浏览 2 评论 0原文

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

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

I was wondering if there is any way to obtain the return value of an outer topic, from within a test of an inner topic. If that was confusing, here's an example:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

勿忘心安 2024-12-09 13:31:21

伪代码

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

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

Pseudo Code:

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

Basically you get the previous topics data in any sub topic. You then need to manually pass it to the vows. Yes it is a pain.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文