Часть теста, которую вы можете сделать, как показано ниже
const sinon = require('sinon');
const chai = require('chai');
const PasswordResets = require('...');
const updatePasswordReset = require('...');
const assert = chai.assert;
describe('test', function () {
const document = 'doc'; // we will pass `document` for `save` callback func
beforeEach(function() {
// we use `sinon.stub` and `yields` for `save` callback function
sinon.stub(PasswordResets.prototype, 'save').yields(null, document);
});
afterEach(function() {
sinon.restore();
})
it('resets password successfully', function() {
return updatePasswordReset('test@gmail.com', '1234', null)
.then(res => {
assert.deepEqual(res, document); // check if the response correct
assert(PasswordResets.prototype.save.calledOnce); // check if it is being called
})
});
});
Ссылка: https://sinonjs.org/releases/v6.1.5/stubs/#stubyieldarg1-arg2-