我有一个设置令牌过期日期的方法:
var jwt = require('jwt-simple');
module.exports = {
setExpirationDate: function(numDays) {
var dateObj = new Date();
console.log(dateObj);
}
}我想在“新日期”声明上写一个断言:
var jwtHelper = require('../../../helpers/jwtToken');
describe('setExpirationDate method', function() {
it('should create date object', function() {
var Date = sinon.spy(Date);
jwtHelper.setExpirationDate(global.TOKEN_EXPIRE_DAYS);
expect(Date).to.be.called;
});
});测试失败的有:
AssertionError:期望间谍至少被呼叫一次,但从未被称为
关于构造器间谍有什么值得关注的地方吗?
发布于 2015-09-01 19:02:15
考虑到您的构造函数绑定到“全局”,这意味着如果您在浏览器上打开开发人员控制台,您应该能够使用相关的函数/构造函数(如:
var Date = new Date();如果是这样的话,实际工作代码可以是:
var Date = sinon.spy(global, 'Date');
expect(Date.called).to.be.equal(true);https://stackoverflow.com/questions/32338427
复制相似问题