Skip to content

Instantly share code, notes, and snippets.

@waldothedeveloper
Created April 1, 2022 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waldothedeveloper/9be846ffa2b2c74e23a203ebaa40e434 to your computer and use it in GitHub Desktop.
Save waldothedeveloper/9be846ffa2b2c74e23a203ebaa40e434 to your computer and use it in GitHub Desktop.
import { render, screen } from "@testing-library/react";
import { ForgotPasswordForm } from "../authentication/forgotPasswordForm";
import React from "react";
import userEvent from "@testing-library/user-event";
jest.mock(`gatsby-plugin-image`, () => {
const React = require(`react`);
const plugin = jest.requireActual(`gatsby-plugin-image`);
const mockImage = ({ imgClassName, ...props }) =>
React.createElement(`img`, { ...props, className: imgClassName });
const mockPlugin = {
...plugin,
GatsbyImage: jest.fn().mockImplementation(mockImage),
StaticImage: jest.fn().mockImplementation(mockImage),
};
return mockPlugin;
});
const user = userEvent.setup();
describe(`Forgot Password Form`, () => {
it(`renders correctly`, () => {
const container = render(<ForgotPasswordForm />);
expect(container).toMatchSnapshot();
});
it(`submit button should be disabled if there's the input field is blank`, () => {
render(<ForgotPasswordForm />);
const submitButton = screen.getByTestId(`submit-button`);
expect(submitButton).toBeDisabled();
});
it(`submit button should be disabled if an invalid email is typed`, () => {
render(<ForgotPasswordForm />);
const inputField = screen.getByTestId(`email-address`);
user.type(inputField, `this is an invalid email address string`);
const submitButton = screen.getByTestId(`submit-button`);
expect(submitButton).toBeDisabled();
});
it(`Submit button should NOT be disabled if a valid email address is used`, async () => {
render(<ForgotPasswordForm />);
// const button = screen.getByTestId(`submit-button`);
const inputEl = screen.getByTestId(`email-address`);
await user.type(inputEl, `test2@gmail.com`);
expect(inputEl.value).toBe(`test2@gmail.com`);
// expect(button).not.toBeDisabled();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment