Created
April 7, 2020 20:46
-
-
Save jensen/80c5b98d46a63a3d55692a1a51b43af5 to your computer and use it in GitHub Desktop.
Example of some React Testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { render, fireEvent } from "@testing-library/react"; | |
import { AddMethod } from "components/request/method"; | |
describe("Adding Requests", () => { | |
it("should call addRequest with GET when the plus button is clicked", () => { | |
const addRequestMock = jest.fn(); | |
const { getByTitle } = render(<AddMethod addRequest={addRequestMock} />); | |
fireEvent.click(getByTitle("Add")); | |
expect(addRequestMock).toBeCalledTimes(1); | |
expect(addRequestMock).toBeCalledWith("GET"); | |
}); | |
it("should call addRequest with the matching method", () => { | |
const addRequestMock = jest.fn(); | |
const { getByText } = render(<AddMethod addRequest={addRequestMock} />); | |
fireEvent.click(getByText("GET")); | |
expect(addRequestMock).toBeCalledTimes(1); | |
expect(addRequestMock).toBeCalledWith("GET"); | |
fireEvent.click(getByText("POST")); | |
expect(addRequestMock).toBeCalledTimes(2); | |
expect(addRequestMock).toBeCalledWith("POST"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Arigato!