我正在尝试测试商店更改。所以,当我派发rateRecipe
时{id: 1, rating: 2}
,我收到以下错误:
TypeError: Cannot set property 'rating' of undefined
切片.js:
it('rating a recipe updates the store', () => {
const state = createState();
state.entities.recipes.list = [{ id: 1, rating: 1 }];
store.dispatch(rateRecipe({ id: '1', rating: 2 }));
expect(recipesSlice().list).toEqual([{ id: 1, rating: 2 }]);
});
slice.test.js:
export const rateRecipe = ({ id, rating }) => recipeRated({ id, rating });