I have a component library that I\'m writing unit tests for using Jest and react-testing-library. Based on certain props or events I want to verify that certain elements aren\'t
You have to use queryByTestId instead of getByTestId.
Here a code example where i want to test if the component with "car" id isn't existing.
describe('And there is no car', () => {
it('Should not display car mark', () => {
const props = {
...defaultProps,
base: null,
}
const { queryByTestId } = render(
,
);
expect(queryByTestId(/car/)).toBeNull();
});
});