I have a reducer with a default initial state defined like this:
const webReducer = (state = {
fetched: false,
data: {}
}, action) => {
switch (action.type) {
case "FETCH_DATA":
state = {
...state,
fetched: action.payload.fetched
};
state.data.push( action.payload.data );
return state;
break;
}
return state;
};
When I run a test to check for the initial state, it pass:
const initialState = {
fetched: false,
data: {}
};
it("Should have a default initial state", () => {
expect( webReducer( undefined, {}) ).toEqual( initialState );
})
However, when I try to test adding data to the state, it return this error:
TypeError: state.data.push is not a function
This is how I'm doing the test:
const object = {
fetched: true,
data: {
config: {size: 10}
}
};
expect(
webReducer( undefined, {
type: "FETCH_DATA",
payload: object
})
).toEqual( object );
Why am i getting this error now, if before i could pass the test just fine? I also tried to pass a default state, like this:
expect(
webReducer( initialState, {
type: "FETCH_DATA",
payload: object
})
).toEqual( object );
But I'm getting the same error.