Приветствую) Изучаю тестирование.
При тестировании редюсера, в терминале выпадает ошибка
(Cannot read property 'wait' of undefined). Почему? Что не так? Помогите пожалуйста :)
Actionexport const GET_ACTIONS_REQUEST = "GET_ACTIONS_REQUEST";
export const GET_ACTIONS_SUCCESS = "GET_ACTIONS_SUCCESS";
const getActions = () => {
return dispatch => {
dispatch({
type: GET_ACTIONS_REQUEST,
payload: {
wait: true
}
});
let act = async () => {
try {
let response = await fetch(`data/actions/actions.json`);
let data = await response.json();
dispatch({
type: GET_ACTIONS_SUCCESS,
payload: {
wait: false,
data: data
}
});
} catch (err) {
console.log(err);
}
};
act();
};
};
export default getActions;
Reducersimport { GET_ACTIONS_REQUEST } from "../../actions/Actions/getActions";
import { GET_ACTIONS_SUCCESS } from "../../actions/Actions/getActions";
export const initialState = {
wait: true,
data: []
};
const getActionsR = (state = initialState, action) => {
switch (action.type) {
case GET_ACTIONS_REQUEST:
return {
...state,
wait: action.payload.wait
};
case GET_ACTIONS_SUCCESS:
return {
...state,
wait: action.payload.wait,
data: action.payload.data
};
default:
return state;
}
};
export default getActionsR;
Testing getActionsRimport getActionsR, { initialState } from "./getActionsR";
describe("тесты getActions", () => {
it("GET_ACTIONS_REQUEST", () => {
const action = {
type: "GET_ACTIONS_REQUEST"
};
expect(getActionsR(initialState, action)).toEqual({
...initialState,
wait: true
});
});
});
TerminalСпасибо :)