Redux-Toolkit操作单元测试

时间:2020-04-18 11:50:14

标签: redux jestjs redux-toolkit

我正在尝试测试商店更改。因此,当我用rateRecipe分派{id: 1, rating: 2}时,出现以下错误:

TypeError: Cannot set property 'rating' of undefined

slice.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 });

0 个答案:

没有答案