Skip to content

Instantly share code, notes, and snippets.

@Frodigo
Created April 6, 2021 18:21
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 Frodigo/d0449891b9aa7d1bbd9955b6c38e8058 to your computer and use it in GitHub Desktop.
Save Frodigo/d0449891b9aa7d1bbd9955b6c38e8058 to your computer and use it in GitHub Desktop.
import React from 'react';
import { render, getByText } from '@testing-library/react';
import ErrorMessage from '../ErrorMessage';
test('ErrorMessage renders correctly', () => {
    const { container } = render(
        <ErrorMessage error={{message: 'Something went wrong.'}}/>
    );
    expect(getByText(container, 'Something went wrong.')).toBeDefined();
    expect(container).toMatchSnapshot();
});
test('ErrorMessage does not render if error message is empty', () => {
    const { container } = render(
        <ErrorMessage error={{message: ''}}/>
    );
    expect(container.firstChild).toBeNull();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment