Skip to content

Commit 8634b48

Browse files
committed
✅ Add simple test for SearchForm
This adds a basic test to make sure the LabelInput is working. To do better integration tests, we'll need something like Puppeteer/browser-based-testing (see testing-library/react-testing-library#376).
1 parent 07c88d9 commit 8634b48

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/components/SearchForm.test.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from "react";
2+
import { render, fireEvent, cleanup } from "@testing-library/react";
3+
import "@testing-library/jest-dom/extend-expect";
4+
import SearchForm from "./SearchForm";
5+
6+
afterEach(cleanup);
7+
8+
test("LabelInput can be focused and accepts text input", () => {
9+
const { getByLabelText } = render(<SearchForm />);
10+
11+
const labelInput = getByLabelText(/label/i);
12+
labelInput.focus();
13+
expect(labelInput).toHaveFocus();
14+
15+
fireEvent.change(labelInput, { target: { value: "foo" } });
16+
expect(labelInput).toHaveValue("foo");
17+
});

0 commit comments

Comments
 (0)