Update unit tests for pagination

This commit is contained in:
Nathan Barber
2021-05-10 17:48:46 -04:00
parent 16c37cd5fe
commit 8d4c276652
13 changed files with 87 additions and 189 deletions

View File

@@ -2,7 +2,7 @@ import React from "react";
import Enzyme, { mount } from "enzyme";
import CreateGroup from "./CreateGroup";
import Adapter from "@wojtekmaj/enzyme-adapter-react-17";
import { Provider, useDispatch } from "react-redux";
import { Provider, useDispatch, useSelector } from "react-redux";
import { createStore } from "redux";
import { HashRouter } from "react-router-dom";
@@ -11,6 +11,7 @@ Enzyme.configure({ adapter: new Adapter() });
jest.mock("react-redux", () => ({
...jest.requireActual("react-redux"),
useDispatch: jest.fn(),
useSelector: jest.fn(),
}));
describe("CreateGroup Component: ", () => {
@@ -22,16 +23,23 @@ describe("CreateGroup Component: ", () => {
<HashRouter>
<CreateGroup
createGroup={callbackSpy}
refreshGroupsData={callbackSpy}
updateGroups={callbackSpy}
history={{ push: () => {} }}
/>
</HashRouter>
</Provider>
);
var mockAppState = () => ({
limit: 3,
});
beforeEach(() => {
useDispatch.mockImplementation((callback) => {
return () => {};
return () => () => {};
});
useSelector.mockImplementation((callback) => {
return callback(mockAppState());
});
});
@@ -52,6 +60,6 @@ describe("CreateGroup Component: ", () => {
input.simulate("change", { target: { value: "" } });
submit.simulate("click");
expect(callbackSpy).toHaveBeenNthCalledWith(1, "");
expect(callbackSpy).toHaveBeenNthCalledWith(2);
expect(callbackSpy).toHaveBeenNthCalledWith(2, 0, 3);
});
});