Created
November 7, 2015 20:04
-
-
Save fastfrwrd/fbfb996ad84c0278eacd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const MyModel = require('./mymodel.js'); | |
describe('My Model', () => { | |
let model; | |
beforeEach(() => { | |
model = new MyModel(); | |
}); | |
describe('hooks', () => { | |
describe('pre save', () => { | |
beforeEach(() => { | |
sinon.spy(modelUtils, 'myMethod'); | |
}); | |
afterEach(() => { | |
modelUtils.myMethod.restore(); | |
}); | |
it('should use modelUtils.myMethod', (done) => { | |
model.save((err) => { | |
try { | |
expect(modelUtils.myMethod).to.have.been.called; | |
} catch (assertErr) { | |
err = err || assertErr; | |
} | |
done(err); | |
}); | |
}); | |
}); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mongoose = require('mongoose'); | |
const Schema = mongoose.Schema; | |
const utils = require('./utils'); | |
const myModelSchema = new Schema({ | |
hello: 'world' | |
}); | |
myModelSchema.pre('save', (next) => { | |
utils.myMethod.call(this); | |
next(); | |
}); | |
module.exports = mongoose.model('MyModel', myModelSchema); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment