私はテストを作成しようとしていますが、テスト環境でmoment("2017-09-10")
を実行するとモーメントオブジェクトが作成されないため、テストを作成できません。そのため、isBetween
は常にfalseです。酵素による試験モーメント
これは、これは私が "瞬間" を使用しています私のテスト
import moment from 'moment'
describe('all dates',() => {
it('returns original statistics',() => {
const statistics = getOverviewStatistics('ctr')(overview)
const statDate = moment(statistics.first().get('date'))
const endDate = moment(statistics.last().get('date'))
const current = filteredStatistics(statistics, statDate, endDate)
const expected = statistics.toJS()
expect(current).toEqual(expected)
})
})
ある
export const filteredStatistics = (data, startDate, endDate) => {
if(startDate === null || endDate === null) return data.toJS()
return data.filter(element => {
const date = moment(element.get("date"))
return date.isBetween(startDate, endDate, "days", "[]")
}).toJS()
}
私の機能である: "^ 2.19.1"、 "酵素":「^ 2.9.1 "、"反応する ":"^15.4.1 " どうすればテストできますか?オブジェクトとの差に
プリントコードを実行し、テストを実行して作成さ
にconsole.log:
console.log('date:', date, 'startDate:', startDate, 'endDate', endDate, 'betweenResult:', date.isBetween(startDate, endDate, 'days', '[]'))
ランニング試験:
PS:私は
与えられた提案を使用するコードを更新し、私は、エラーが見つかりました:私は、終了日を2016年ではなく2017 u.u」申し訳ありませんが、助けてくれてありがとうみんなを入れていました!
エラーが発生しますか?どのようにテストのための瞬間を定義していますか? – jmargolisvt
@jmargolisvtエラーを投げているわけではありません。 empy配列を返すので、単純に渡されません。私はこのような瞬間を定義しています: 'moment'からのインポートモーメント – Marina