Skip to content

Instantly share code, notes, and snippets.

@aherve
Created March 12, 2016 11:18
Show Gist options
  • Select an option

  • Save aherve/632ac6f29bb406d9d79b to your computer and use it in GitHub Desktop.

Select an option

Save aherve/632ac6f29bb406d9d79b to your computer and use it in GitHub Desktop.
describe('postCreatePlugin', function () {
let MyModel, spy1, spy2
before(function(done) {
const MySchema = new mongoose.Schema({
foo: String,
})
MySchema.plugin(postCreatePlugin)
MyModel = mongoose.model('MyModel', MySchema)
spy1 = sinon.spy()
spy2 = sinon.spy()
MyModel.schema.addPostCreate(spy1)
MyModel.schema.addPostCreate(spy2)
done()
})
it('works', function (done) {
const obj = new MyModel({foo: 'bar'})
obj.save((err, obj) => {
should.not.exist(err)
should.exist(obj)
obj.should.have.property('foo', 'bar')
spy1.callCount.should.eql(1)
spy2.callCount.should.eql(1)
obj.foo = 'bar2'
obj.save((err, obj) => {
should.not.exist(err)
should.exist(obj)
obj.should.have.property('foo', 'bar2')
spy1.callCount.should.eql(1)
spy2.callCount.should.eql(1)
done()
})
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment