我有一个React商店,代码结构很简单:
get: function() {
var getA = new Promise( (resolve, reject) => {
RestApi.post(url, data, re => resolve(re), re=>reject(re)); // this makes an ajax calls to the rest api
} );
var getB = new Promise( (resolve, reject) => {
RestApi.post(url, data, re => resolve(re), re=>reject(re));
} );
var getC = new Promise( (resolve, reject) => {
RestApi.post(url, data, re => resolve(re), re=>reject(re));
} );
Promise.all( getA, getB, getC ).then( values => {
this.set(values);
} );
},
set: function(value){
// code to set the store.
}
所以我正在尝试使用JEST为这段代码添加单元测试,但是我完全迷失了JEST / Jasmine如何使用promise,以及如何在promise中测试ajax?