I'm following a tutorial on React.js testing Library and trying to follow along in Typescript. Although after following along with the first test I'm already encountering a few issues and am wondering what should be different in a test written in Typescript.
App.ts
function App() {
return (
<div className="container my-5">
<form>
<div className="mb-3">
<label htmlFor="email" className="form-label">
Email Address
</label>
<input
type="email"
id="email"
name="email"
className="form-control"
/>
</div>
<div className="mb-3">
<label htmlFor="password" className="form-label">
Password
</label>
<input
type="password"
id="password"
name="password"
className="form-control"
/>
</div>
</form>
</div>
);
}
export default App;
App.test.tsx
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/);
expect(emailInputElement.value).toBe("");
expect(passwordInputElement.value).toBe("");
});
I'm receiving an error "Property 'value' does not exist on type 'HTMLElement" on:
expect(emailInputElement.value).toBe("");
expect(passwordInputElement.value).toBe("");
Do these need to be explained differently on Typescript?