I am a newbie in unit testing and I have 2 files:
RestaurantReducer
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;
and 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
})
})
}
}
and my test:
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: []
});
});
});
I do not know how to go about it. Can you check the connection or data that come from the server? Can such data simulate but they are dynamic.