【发布时间】:2018-02-22 03:21:14
【问题描述】:
我是单元测试的新手,我有 2 个文件:
餐厅减速器
import * as Const from '../constants/Const'
const RestaurantReducer = (state = {
restaurantList: []
}, action) => {
switch (action.type) {
case Const.GET_RESTAURANT_LIST: {
return {
...state,
restaurantList: action.payload
};
}
}
return state;
};
export default RestaurantReducer;
和 RestauntActions.js
export function getRestaurantList() {
return dispatch => {
axios({
method: "GET",
url: URLS.URL_RESTAURANT_LIST
}).then((response) => {
dispatch({
type: CONST.GET_RESTAURANT_LIST,
payload: response.data
})
})
}
}
和我的测试:
describe('request reducer', () => {
it('Default values', () => {
expect(restReducer(undefined, {type: 'unexpected'})).toEqual({
restaurantList: []
});
});
// ---------------- Dont know how to check this -------------------
it('Async data',async () => {
expect(restReducer(undefined, {
type: 'GET_RESTAURANT_LIST',
})).toEqual({
...state,
restaurantList: []
});
});
});
我不知道该怎么做。您可以检查来自服务器的连接或数据吗?这些数据可以模拟,但它们是动态的。
【问题讨论】:
标签: javascript reactjs testing jestjs