This is my foree' into mongoose methods. Any suggestions really appreciated. Mocha is complaining about it cannot find my model collection (in my code is the "this.model('User'.... line)). I am using sinon stub to stub out Model and method name.
Unit testing the schema (validating validators) went well. I am trying to get my head wrapped around a simple mongoose.method.
Mongoose method (bottom portion of mongoose schema file):
userSchema.methods.findUser = (cb) => {
this.model('User').findOne({
lname: this.lname
}, (err, val) => {
cb(!!val);
});
};
module.exports = mongoose.model('User', userSchema);
My test for this method:
it('gets a User', (done) => {
sinon.stub(User, 'findOne');
let u = new User({ lname: 'Pickles' });
u.findUser();
sinon.assert.calledWith(User.findOne, { lname: 'Pickles' });
done();
});
