I am implementing React testing library as follows:
const onCardClick = jest.fn();
afterEach(cleanup);
describe('Card', () => {
test('renders quote card and allows click', () => {
const { getByTestId } = render(<Card onClick={onCardClick} />);
fireEvent.click(getByTestId('card-root'));
expect(onCardClick.mock.calls.length).toBe(1);
});
test('renders card passes index on click', () => {
const { getByTestId } = render(
<Card onClick={onCardClick} index={2} />
);
fireEvent.click(getByTestId('card-root'));
expect(onCardClick.mock.calls.length).toBe(1);
expect(onCardClick.mock.calls[0][0]).toBe(2);
});
});
Could there be a way that both test cases are not dependent on each other, as currently when first is run the test is passed as it is clicked one time, when second test is run now click is expected as 2(It should be expected as 1 only as a separate click) . I want these test cases not to be dependent on each other.