diff --git a/src/components/App/App.test.tsx b/src/components/App/App.test.tsx index ea40ae6..215d71f 100644 --- a/src/components/App/App.test.tsx +++ b/src/components/App/App.test.tsx @@ -13,7 +13,6 @@ describe("App", () => { it("renders Loader when userProfile not loaded", () => { const { container } = setup({ userProfile: {}, - users: { list: null }, }); const app = container.querySelector(".loader"); expect(app).toBeInTheDocument(); @@ -23,7 +22,6 @@ describe("App", () => { userProfile: { username: "Steve", }, - users: { list: null }, }); const app = container.querySelector(".app"); expect(app).toBeInTheDocument(); diff --git a/src/pages/LandingPage/LandingPage.test.tsx b/src/pages/LandingPage/LandingPage.test.tsx index 773a72a..b5faa68 100644 --- a/src/pages/LandingPage/LandingPage.test.tsx +++ b/src/pages/LandingPage/LandingPage.test.tsx @@ -12,10 +12,7 @@ const setup = (initialState = {}) => describe("LandingPage", () => { it("renders", () => { - setup({ - userProfile: {}, - users: { list: null }, - }); + setup(); const heading = screen.getByText("Landing page"); expect(heading).toBeInTheDocument(); diff --git a/src/state/rootReducer.ts b/src/state/rootReducer.ts index 4f04152..a6f2db4 100644 --- a/src/state/rootReducer.ts +++ b/src/state/rootReducer.ts @@ -3,7 +3,9 @@ import { combineReducers } from "@reduxjs/toolkit"; import userProfile from "./userProfile/reducer"; import users from "./users/reducer"; -const rootReducer = combineReducers({ userProfile, users }); +export const reducers = { userProfile, users } as const; + +const rootReducer = combineReducers(reducers); export type RootState = ReturnType; export default rootReducer; diff --git a/src/state/userProfile/selectors.test.ts b/src/state/userProfile/selectors.test.ts index 142bb36..99798bf 100644 --- a/src/state/userProfile/selectors.test.ts +++ b/src/state/userProfile/selectors.test.ts @@ -1,15 +1,15 @@ import { getUsername } from "./selectors"; - +import mockState from "utilities/test/mockState"; import { RootState } from "../rootReducer"; describe("UserProfile selectors", () => { describe("getUsername", () => { it("should return username", () => { const state: RootState = { + ...mockState, userProfile: { username: "Steve", }, - users: { list: null }, }; expect(getUsername(state)).toBe("Steve"); }); diff --git a/src/utilities/test/mockState.ts b/src/utilities/test/mockState.ts new file mode 100644 index 0000000..b129078 --- /dev/null +++ b/src/utilities/test/mockState.ts @@ -0,0 +1,9 @@ +import { initialState as userProfileInitialState } from "state/userProfile/reducer"; +import { initialState as usersInitialState } from "state/users/reducer"; + +const state = { + userProfile: userProfileInitialState, + users: usersInitialState, +}; + +export default state; diff --git a/src/utilities/test/renderConnected.tsx b/src/utilities/test/renderConnected.tsx index b0f5d48..90c74f4 100644 --- a/src/utilities/test/renderConnected.tsx +++ b/src/utilities/test/renderConnected.tsx @@ -4,6 +4,8 @@ import { Provider } from "react-redux"; import configureStore, { MockStore } from "redux-mock-store"; import thunk from "redux-thunk"; +import { reducers } from "state/rootReducer"; + interface RenderConnected { ui: JSX.Element; initialState: Record; @@ -18,7 +20,7 @@ const middleware = [thunk]; const mockStore = configureStore(middleware); export const makeStore = (initialState: Record): MockStore => - mockStore(initialState); + mockStore({ ...reducers, ...initialState }); const renderConnected = ({ ui,