间隔,我需要帮助编写基于一个initialDueDate
不同的时间间隔(quarterly
,yearly
和monthly
)得到nextDueDate
的功能。该方法看起来像计算nextDueDate基于使用Moment.js
伪码 -
如果initialDueDate
是在未来,返回initialDueDate
否则,如果时间间隔为quarterly
,不断增加3个月initialDueDate
,直到你发现在该日期未来。
这是本次测试我试图通过:
describe('time helper',() => {
describe('when initialDueDate is in the future',() => {
it('returns the initialDueDate when in the future',() => {
const fakeNow = moment({ y: 2016, M: 0, d: 0 });
Date.now = jest.fn(() => fakeNow.valueOf());
const initialDueDate = moment({ y: 2016, M: 0, d: 14 });
const value = time.calculateNextDueDate(initialDueDate, 'quarterly');
expect(value).toEqual(initialDueDate);
});
});
describe('when initialDueDate is in the past',() => {
it('returns the correct date when interval is quarterly');
it('returns the correct date when interval is monthly');
it('returns the correct date when interval is yearly');
it('throws an error when initialDueDate parameter is invalid');
it('throws an error when interval parameter is invalid');
});
看起来你已经开始了......你有什么问题? –