【发布时间】:2018-03-19 20:02:55
【问题描述】:
我有这个随机函数。我怎样才能为此创建一个单元测试? (必须使用 Jest)
random = (array) => {
for(let val of array){
var change_percent = Math.floor(Math.random() * (1001) + -500)/100; // random a rumber from -5 to 5
val.change_percent = change_percent;
val.volume = val.volume + Math.floor(Math.random()*(20) + 10); // random increase volume from 10 to 30
val.price = (parseFloat(val.price) + parseFloat(val.change)).toFixed(2);
val.change = (val.price * change_percent /100).toFixed(2);
}
}
【问题讨论】:
标签: javascript unit-testing ecmascript-6 jestjs