3

I would like to write a test that verifies that a certain property will be saved using Mongoose, for instance:

var newUser = new userModel({
    id: /*something*/,
    gu: true
});

newUser.save(function (err, user) {
    /* ... */
    res.send(user.id);
});

In my tests, I want to make sure that the gu property is set to true. I can easily stub save(), however I can't verify that gu is set to true since save() is a function of the object and therefore it is not part of the parameters. Any ideas?

Nepoxx
  • 4,849
  • 5
  • 42
  • 61
  • This has been answered here: http://stackoverflow.com/questions/11318972/stubbing-a-mongoose-model-with-sinon – MaxM Jan 23 '15 at 15:20
  • 2
    No it hasn't. I even asked a follow-up question on that page as a follow-up. The distinction is that I want to spy on the values saved because I want to make sure, in my case, that `gu` is set to true. Also, it doesn't explain how to do it with chained calls. – Nepoxx Jan 24 '15 at 18:20
  • Isn't possible to access the this context of the call through sinon? It should hold all the properties. – MaxM Jan 24 '15 at 23:20

0 Answers0