-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.test.js
31 lines (24 loc) · 888 Bytes
/
App.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import "@testing-library/react/cleanup-after-each";
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import { render, fireEvent } from "@testing-library/react";
it("renders without crashing", () => {
const div = document.createElement("div");
ReactDOM.render(<App />, div);
ReactDOM.unmountComponentAtNode(div);
});
// Passes
it("calls onSubmit when the button is clicked", () => {
const onSubmit = jest.fn();
const { getByTestId } = render(<App onSubmit={onSubmit} />);
fireEvent.click(getByTestId("submit-button"));
expect(onSubmit).toHaveBeenCalled();
});
// Fails
it("calls onSubmit when the span inside the button is clicked", () => {
const onSubmit = jest.fn();
const { getByTestId } = render(<App onSubmit={onSubmit} />);
fireEvent.click(getByTestId("submit-button-span"));
expect(onSubmit).toHaveBeenCalled();
});