【发布时间】:2019-05-29 11:15:53
【问题描述】:
我是单元测试新手,我正在为返回日期的函数实施单元测试。
const getLastHour = () => {
const date = new Date().getTime() - 3600000;
return date;
};
我做了这样的东西,但它不起作用
describe('getLastHour', () => {
const getLastHour = mobileArticleService.__get__('getLastHour');
const getTime = sinon.stub(2019052906);
const Date = sinon.stub({ getTime });
before(() => {
mobileArticleService.__set__({
Date,
getTime,
});
});
it('should return date with hours ', () => {
expect(Date).to.be.called;
expect(getTime).to.be.called;
});
});
【问题讨论】:
-
“不起作用”以什么方式?会发生什么,您期望会发生什么?即使它应该通过,测试是否会失败,或者相反?它会抛出错误吗?