import React from 'react'; import { render, cleanup } from '@testing-library/react'; import '@testing-library/jest-dom/extend-expect'; import { Loader } from './index'; import { LoaderSizes } from 'types'; afterEach(cleanup); test('should take a snapshot', () => { const { asFragment } = render(
); expect(asFragment()).toMatchSnapshot(); }); describe('tests message prop', () => { test('renders a Loader with message', () => { const { getByTestId } = render(
); expect(getByTestId('loader-container')).toBeInTheDocument(); expect(getByTestId('loader-container').textContent).toBe('Loading...'); }); test('renders a Loader with no message', () => { const { getByTestId } = render(
); expect(getByTestId('loader-container')).toBeInTheDocument(); expect(getByTestId('loader-container').textContent).toBeFalsy(); }); }); describe('tests isLoading prop', () => { test('does not render a Loader when isLoading={false}', () => { const { getByTestId, queryByTestId } = render(
); expect(queryByTestId('loader-container')).toBeFalsy(); expect(getByTestId('child-id')).toBeInTheDocument(); }); test('renders a Loader when isLoading={true}', () => { const { getByTestId } = render(
); expect(getByTestId('loader-container')).toBeInTheDocument(); }); }); describe('tests size prop', () => { test('tests a small loader', () => { const { getByTestId } = render(
); expect(getByTestId('loader')).toBeInTheDocument(); expect(getByTestId('loader')).toHaveStyle({ 'border-width': '0.25rem', height: '1.8rem', width: '1.8rem', }); }); test('tests a medium loader', () => { const { getByTestId } = render(
); expect(getByTestId('loader')).toBeInTheDocument(); expect(getByTestId('loader')).toHaveStyle({ 'border-width': '0.325rem', height: '2.4rem', width: '2.4rem', }); }); test('tests a large loader', () => { const { getByTestId } = render(
); expect(getByTestId('loader')).toBeInTheDocument(); expect(getByTestId('loader')).toHaveStyle({ 'border-width': '0.4rem', height: '3.2rem', width: '3.2rem', }); }); });