import React from "react";
import { render } from "@testing-library/react";
import { Form } from "../../components";
jest.mock("react-router-dom");
describe("<Form />", () => {
it("Renders the <Form/> with populated data", () => {
const { container, getByText, getByPlaceholderText } = render(
<Form>
<Form.Title>Sign in now</Form.Title>
<Form.Base>
<Form.Input placeholder="Email address" onChange={() => {}} />
<Form.Input
type="password"
placeholder="Password"
onChange={() => {}}
/>
<Form.Submit type="submit" disabled>
Sign In
</Form.Submit>
</Form.Base>
<Form.Text>
New to Netflix? <Form.Link to="/signup">Sign up now.</Form.Link>
</Form.Text>
<Form.TextSmall>
This page is protected by Google reCAPTCHA to ensure you're not a bot.
Learn more.
</Form.TextSmall>
</Form>
);
expect(
getByText(
"This page is protected by Google reCAPTCHA to ensure you're not a bot. Learn more."
)
).toBeTruthy();
expect(getByText("Sign in now")).toBeTruthy();
expect(getByText("Sign in")).toBeTruthy();
expect(getByText("Sign in now").disabled).toBeTruthy();
});
});
The error is the following:
Error: Uncaught [Error: ForwardRef(Link)(…): Nothing was returned from render. This usually means a return statement is missing. Or, to render nothing, return null.]
I am rendering a form, I don´t understand why it says that. I also tried to return the form inside the render but that did not work.
I am using jest.mock(“react-router-dom”); to do that and still have issues.
In any case, I am following a youtube tutorial and this piece of code work for the author of this tutorial. I am comparing my code to his on our github repos and they are the same.
import React from "react";
import { render } from "@testing-library/react";
import { Form } from "../../components";
import { Router } from "react-router-dom";
// jest.mock("react-router-dom");
describe("<Form />", () => {
it("Renders the <Form/> with populated data", () => {
const { container, getByText, getByPlaceholderText } = render(
<Router>
<Form>
<Form.Title>Sign in now</Form.Title>
<Form.Base>
<Form.Input placeholder="Email address" onChange={() => {}} />
<Form.Input
type="password"
placeholder="Password"
onChange={() => {}}
/>
<Form.Submit type="submit" disabled>
Sign in
</Form.Submit>
</Form.Base>
<Form.Text>
New to Netflix? <Form.Link to="/signup">Sign up now.</Form.Link>
</Form.Text>
<Form.TextSmall>
This page is protected by Google reCAPTCHA to ensure you're not a
bot. Learn more.
</Form.TextSmall>
</Form>
</Router>
);
expect(
getByText(
"This page is protected by Google reCAPTCHA to ensure you're not a bot. Learn more."
)
).toBeTruthy();
expect(getByText("Sign in now")).toBeTruthy();
expect(getByText("Sign in")).toBeTruthy();
expect(getByText("Sign in now").disabled).toBeTruthy();
expect(getByPlaceholderText("Email address")).toBeTruthy();
expect(getByPlaceholderText("Password")).toBeTruthy();
expect(container.firstChild).toMatchSnapshot();
});
This comes up:
Error: Uncaught [TypeError: Cannot read properties of undefined (reading 'pathname')]