jeudi 13 juin 2019

Best practice to check that a component is not rendered

Let's assume that a component returns null in render method, based on some prop.

What is the best way to use expect in order to ensure that component is not rendered?

Example:

import React from 'react';
import { render, fireEvent } from '@testing-library/react';
import Pagination from '../Pagination';

it('should not render if totaPages is 0', () => {
  const { container } = render(<Pagination activePage={1} totalPages={0} />);
  expect(container.firstChild).toBeNull();
});

Is the above code enough?

Aucun commentaire:

Enregistrer un commentaire