Hızlı yanıt: kod örneği
You are getting this error because and returns object and it doesn´t have prop.There are 2 ways to get it working:
screen.getByRole
screen.getByLabelText
HTMLElement
value
- explicitly define the return type as (it has value prop).
HTMLInputElement
import { render, screen } from "@testing-library/react";import App from "./App";test("inputs should be initially empty", () => { render(<App />); const emailInputElement = screen.getByRole<HTMLInputElement>("textbox"); const passwordInputElement = screen.getByLabelText<HTMLInputElement>(/password/i); expect(emailInputElement.value).toBe(""); expect(passwordInputElement.value).toBe("");});
- Use library -> it provides a set of custom jest matchers that you can use to extend jest. You can check more here.
@testing-library/jest-dom
import "@testing-library/jest-dom/extend-expect";import { render, screen } from "@testing-library/react";import App from "./App";test("inputs should be initially empty", () => { render(<App />); const emailInputElement = screen.getByRole("textbox"); const passwordInputElement = screen.getByLabelText(/password/i); expect(emailInputElement).toHaveValue(""); expect(passwordInputElement).toHaveValue("");});