2019-06-12 11:27:28 +02:00
|
|
|
import sinon from 'sinon';
|
|
|
|
import 'sinon-mongoose';
|
|
|
|
|
|
|
|
// Import the actual model to be mocked
|
|
|
|
const Project = jest.requireActual('../project').default;
|
|
|
|
|
|
|
|
// Wrap Project in a sinon mock
|
|
|
|
// The returned object is used to configure
|
|
|
|
// the mocked model's behaviour
|
|
|
|
export function createMock() {
|
|
|
|
return sinon.mock(Project);
|
|
|
|
}
|
|
|
|
|
2019-08-30 20:26:57 +02:00
|
|
|
// Wraps the Project.prototype i.e. the
|
|
|
|
// instance methods in a mock so
|
|
|
|
// Project.save() can be mocked
|
|
|
|
export function createInstanceMock() {
|
|
|
|
// See: https://stackoverflow.com/questions/40962960/sinon-mock-of-mongoose-save-method-for-all-future-instances-of-a-model-with-pro
|
|
|
|
Object.defineProperty(Project.prototype, 'save', {
|
|
|
|
value: Project.prototype.save,
|
|
|
|
configurable: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
Object.defineProperty(Project.prototype, 'remove', {
|
|
|
|
value: Project.prototype.remove,
|
|
|
|
configurable: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
return sinon.mock(Project.prototype);
|
|
|
|
}
|
|
|
|
|
2019-06-12 11:27:28 +02:00
|
|
|
// Re-export the model, it will be
|
|
|
|
// altered by mockingoose whenever
|
|
|
|
// we call methods on the MockConfig
|
|
|
|
export default Project;
|