开发者

Vows.js - Number of args this.callback returns to topic versus vow

From the vows site: "When this.callback is called, it passes on the arguments it received to the tes开发者_开发百科t functions, one by one, as if the values were returned by the topic function itself." In other words if we're using the request library to handle our http requests, our topic and vow can look like:

'When I make a valid request':
  topic: ->
    request
      uri: someURL
      method: "GET"
    , @callback
    return undefined # necessary because I'm using coffeescript

  "It should respond with a 200":
    (err, resp, body) ->
      assert.equal resp.statusCode, "200"

But topics that are strung together seem to play by different rules. They only seem to pass along one argument. Here's an example from the Vows site:

topic: function () {
  fs.stat('~/FILE', this.callback);
  }, 
  'after a successful `fs.stat`': {
    topic: function (stat) {
      fs.open('~/FILE', "r", stat.mode, this.callback);}, etc

So instead of the second topic getting arugments like (err, stat), it just gets (stat).

Anybody know why this is the case?


In my experience, Vows omits the err argument when calling sub-topics.

This probably solves the problem of requiring that nested topics take every err argument with every extra parent. You don't want this situation:

topic: (err, topic1, err, topic2, err, topic3)

Instead, just work with the non-err arguments.

topic: (topic1, topic2, topic3)

This is somewhat confusing since Vows automatically intercepts a non-null err argument and fails the test. So you'll never be able to use the err argument anyway.


So you'll never be able to use the err argument anyway.

How did Vows determine that the argument is err.

Is it by name? Or always the null-first-argument, which may not work in cases which do not return err as first arg?

Thanks,

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜