2

From the vows site: "When this.callback is called, it passes on the arguments it received to the test 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?

David EGP
  • 6,799
  • 1
  • 18
  • 7
  • I wonder if that is just an error on their part. i.e. that they don't check the consistency of the examples that they have provided. Have you tried similar things using your own code in order to confirm? – momo Sep 03 '11 at 12:46
  • Yeah, that's how I found out about it. My code kept blowing up when I tried to access the second argument from the callback. – David EGP Sep 03 '11 at 14:03

2 Answers2

1

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.

0

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,

sowdri
  • 2,193
  • 5
  • 23
  • 36