我有一个测试正在监视一个存根的方法。该方法正在伪造依赖项。我可以验证该方法实际上正在被调用。我什至可以验证它是用预期的参数调用的。true
但是,间谍在查看called
或时没有提供calledWith
。
它mailerStub
是代理mailer
依赖项的方法。
我什至console.log
为 the放置了一个spy.displayName
,它mailer
和预期的一样。
我在这里做错了什么?
var proxyquire = require('proxyquire');
var expect = require('chai').expect;
var sinon = require('sinon');
var mockReq = require('./../mockReq');
var mockRes = require('./../mockRes');
var utils = require('./../utils');
var config = require('./../../server-config');
var mailerErr;
var mailerTemplate;
var mailerStub = function mailer(to, subject, html, callback) {
callback(mailerErr);
};
var emailTemplatesErr;
var templateErr;
var templateHtml;
var emailTemplatesStub = function emailTemplates(root, callback) {
callback(emailTemplatesErr, function template(name, locals, callback) {
callback(templateErr, templateHtml);
})
};
var sut = proxyquire('./../../middleware/sendEmail', {
'../mailer': mailerStub,
'email-templates': emailTemplatesStub
});
describe('middleware/sendEmail', function sendEmailSpec() {
beforeEach(function() {
mailerErr = false;
mailerTemplate = undefined;
emailTemplatesErr = false;
templateErr = false;
templateHtml = undefined;
});
it('should send an email', function(done) {
var req = new mockReq();
var res = new mockRes(next);
res.email = {
templateName: 'template-name',
to: 'test@test.com',
subject: 'some subject',
locals: {
firstName: 'test'
}
};
templateHtml = 'HTML';
var spy = sinon.spy(mailerStub);
sut(req, res, next);
function next(msg) {
console.log(spy.displayName);
expect(msg).to.be.false;
expect(spy.called).to.be.true;
//expect(spy.calledWith(res.email.to, res.email.subject, templateHtml)).to.be.true;
done();
}
});
});