【发布时间】:2021-06-14 10:04:43
【问题描述】:
我想用 Jest 测试我今天和前一天的时间跨度,但我不知道该怎么做。 也许有人可以告诉我它是如何工作的?我是编写单元测试的新手..
这是我要测试的代码:
export const getToday = () => {
const today = new Date();
return today;
}
export const getDayBefore = (date) => {
const day = new Date(date);
day.setDate(date.getDate() - 1);
return day;
}
这是我现在所做的,但它不起作用。
describe('getToday', () => {
it('should checks "today"', () => {
const ts1 = Date.now();
expect(ts1).toEqual(getToday);
})
});
【问题讨论】:
-
不应该
expect(ts1).toEqual(getToday);是expect(ts1).toEqual(getToday());?