Reconfigure tests to work with hook approach

This commit is contained in:
Nathan Barber
2021-04-07 15:25:21 -04:00
parent b230745d64
commit 4768751125
13 changed files with 129 additions and 87 deletions

View File

@@ -0,0 +1,34 @@
import React from "react";
import Enzyme, { mount, shallow } from "enzyme";
import CreateGroup from "./CreateGroup.pre";
import Adapter from "@wojtekmaj/enzyme-adapter-react-17";
Enzyme.configure({ adapter: new Adapter() });
describe("CreateGroup Component: ", () => {
var mockAsync = () =>
jest.fn().mockImplementation(() => Promise.resolve({ key: "value" }));
var createGroupJsx = (callbackSpy) =>
<CreateGroup
createGroup={callbackSpy}
refreshGroupsData={callbackSpy}
history={{push: () => {}}}
/>
it("Renders", () => {
let component = shallow(createGroupJsx())
expect(component.find(".container").length).toBe(1)
})
it("Calls createGroup and refreshGroupsData on submit", () => {
let callbackSpy = mockAsync(),
component = shallow(createGroupJsx(callbackSpy)),
input = component.find("input").first(),
submit = component.find("#submit").first()
input.simulate("change", { target: { value: "" } })
submit.simulate("click")
expect(callbackSpy).toHaveBeenNthCalledWith(1, "")
expect(callbackSpy).toHaveBeenNthCalledWith(2)
})
})