Using Vows to test Mongoose models Using Vows to test Mongoose models mongoose mongoose

Using Vows to test Mongoose models


That's not how vows works. vows cannot be asynchronous. You should use sub topics for asynchronous testing

Pseudo code (I can't write CS)

topic: () -> new Project()'should have name': {  'topic': (topic) ->    topic.name = "some name"    topic.save    Project.findById topic.id, this.callback    return;  'that can be saved': (err, proj) ->    console.log "SHOULD RUN"    assert.equal "some name", proj.name}

As you can see you create a new context with a topic that does asynchronous activity. You then vow things about the data your asynchronous activity returns.


One problem I see is that topic.save is a no-op—you probably meant topic.save(). Another, more serious problem is that you need to use Vows' this.callback for async tests; see Raynos' answer.

You also need to be aware that Vows ends a test when it gets any return value (other than undefined, which is equivalent to not returning anything). Because of CoffeeScript's implicit returns, this means you have to be very careful. (I'm on record as supporting an alternate -/> syntax for functions with no return value; see issue 899.)