diff --git a/template/src/features/counter/Counter.test.tsx b/template/src/features/counter/Counter.test.tsx index eb1977f..7d0ca78 100644 --- a/template/src/features/counter/Counter.test.tsx +++ b/template/src/features/counter/Counter.test.tsx @@ -1,15 +1,10 @@ import { screen, fireEvent, wait } from "@testing-library/react"; import Counter from "./Counter"; import React from "react"; -import counterReducer, { - increment, - decrement, - fetchValueStart, - fetchValueSuccess, - fetchValueError -} from "./CounterSlice"; +import counterReducer, { increment, decrement } from "./CounterSlice"; import { renderWithRedux, rootInitialState } from "utils/test-helpers"; import axios from "axios"; +import { fetchInitial } from "./CounterSlice"; jest.mock("axios"); const mockedAxios = axios as jest.Mocked; @@ -63,10 +58,9 @@ describe("", () => { // https://github.com/testing-library/react-testing-library#complex-example await wait(() => null, { timeout: 500 }); - expect(mockStore.getActions()).toEqual([ - { type: fetchValueStart.type, payload: undefined }, - { type: fetchValueSuccess.type, payload: name.length } - ]); + expect(mockStore.getActions()[0].type).toEqual(fetchInitial.pending.type); + expect(mockStore.getActions()[1].type).toEqual(fetchInitial.fulfilled.type); + expect(mockStore.getActions()[1].payload).toEqual(name.length); }); test("slow fetch error", async () => { @@ -82,10 +76,9 @@ describe("", () => { // https://github.com/testing-library/react-testing-library#complex-example await wait(() => null, { timeout: 500 }); - expect(mockStore.getActions()).toEqual([ - { type: fetchValueStart.type, payload: undefined }, - { type: fetchValueError.type, payload: "Something went wrong." } - ]); + expect(mockStore.getActions()[0].type).toEqual(fetchInitial.pending.type); + expect(mockStore.getActions()[1].type).toEqual(fetchInitial.rejected.type); + expect(mockStore.getActions()[1].payload).toEqual("Something went wrong."); }); }); @@ -94,7 +87,7 @@ describe("CounterSlice", () => { expect( counterReducer( { ...rootInitialState.counter, loading: false }, - fetchValueStart + fetchInitial.pending ) ).toEqual({ ...rootInitialState.counter, loading: true }); }); @@ -103,7 +96,7 @@ describe("CounterSlice", () => { expect( counterReducer( { ...rootInitialState.counter, loading: true }, - { type: fetchValueSuccess, payload: 100 } + { type: fetchInitial.fulfilled.type, payload: 100 } ) ).toEqual({ ...rootInitialState.counter, loading: false, value: 100 }); }); @@ -112,7 +105,7 @@ describe("CounterSlice", () => { expect( counterReducer( { ...rootInitialState.counter, loading: true }, - { type: fetchValueError, payload: "Some error message." } + { type: fetchInitial.rejected, payload: "Some error message." } ) ).toEqual({ ...rootInitialState.counter, diff --git a/template/src/features/counter/Counter.tsx b/template/src/features/counter/Counter.tsx index 8d10fbe..5c18820 100644 --- a/template/src/features/counter/Counter.tsx +++ b/template/src/features/counter/Counter.tsx @@ -1,8 +1,7 @@ import React from "react"; import { useDispatch, useSelector } from "react-redux"; import styles from "./Counter.module.scss"; -import { increment, decrement } from "./CounterSlice"; -import { fetchInitialValue } from "./CounterActions"; +import { increment, decrement, fetchInitial } from "./CounterSlice"; import { RootState } from "store"; const Counter: React.FC = () => { @@ -46,7 +45,7 @@ const Counter: React.FC = () => {