1
date.js テストは、JSの日付
class DateHelper {
constructor() {
this.months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
}
postedOn(from) {
const date = new Date(from);
const day = date.getDate();
const month = this.months[date.getMonth()];
const year = date.getFullYear();
if (year === new Date().getFullYear()) {
return `${day} ${month}`;
}
return `${day} ${month} ${year}`;
}
}
date_spec.js
describe('',() => {
it('',() => {
const from = 'Wed Feb 25 2015 00:38:24 GMT+0200 (EET)';
expect(newDateHelper.postedOn(from)).to.equal('25 Feb 2015');
});
it('',() => {
const from = 'Wed Feb 25 2017 00:38:24 GMT+0200 (EET)';
expect(newDateHelper.postedOn(from)).to.equal('25 Feb');
});
});
すべてのテストが現在渡しているが、postedOn
は現在の年と比較するので、私はこれらのテストを更新する必要があります毎年。これをどうすれば解決できますか?
これについては考えていません。助けてくれてありがとう) –
@ArtemGurzhiiあなたが正しい場合は正しい答えとしてマークすることができます) – Antonio