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?
If you use jest-dom you can do expect(container).toBeEmptyDOMElement()
. I find it a bit more readable, but your solution works too
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With