-
Notifications
You must be signed in to change notification settings - Fork 1
/
find-elements.rtl.test.js
31 lines (23 loc) · 1.16 KB
/
find-elements.rtl.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 React from "react";
import { render, cleanup } from "@testing-library/react";
import FindElementsFoo from "../../components/find-elements";
afterEach(cleanup);
describe("These test suite(s) is/are designed to demonstrate a few methods to access certain elements in the DOM", () => {
it("getByLabelText", () => {
const { getByLabelText } = render(<FindElementsFoo />);
expect(getByLabelText("Username")).toBeInTheDocument();
expect(getByLabelText(/user/i)).toBeInTheDocument();
});
it("getByTestId", () => {
const { getByTestId } = render(<FindElementsFoo />);
expect(getByTestId("username-label")).toBeInTheDocument();
expect(getByTestId(/username/i)).toBeInTheDocument();
});
it("getByPlaceholderText", () => {
const { getByPlaceholderText } = render(<FindElementsFoo />);
expect(getByPlaceholderText("Username")).toBeInTheDocument();
expect(getByPlaceholderText(/username/i)).toBeInTheDocument();
expect(getByPlaceholderText("Username")).toHaveAttribute("id", "username");
expect(getByPlaceholderText(/usern/i)).toHaveAttribute("type", "text");
});
});