React testing library - check the existence of empty div

Update

Use toBeEmptyDOMElement since toBeEmtpy has been deprecated.


You can use jest-dom's toBeEmpty:

const { container } = render(<MyComp ItemLength={1} />)
expect(container.firstChild).toBeEmpty()

The following should work as well without extending jest's expect:

const { container } = render(<MyComp ItemLength={1} />)
expect(container.firstChild).toBeNull();

Update: the new way in 2020

import { screen } from '@testing-library/react';

...

render(<MyComp ItemLength={1} />);

const child = screen.queryByTestId('data-testid-attribute-value');

expect(child).not.toBeInTheDocument();