import { render, screen, cleanup } from '@testing-library/react';
import GroceryList from './components/GroceryList';
import userEvent from '@testing-library/user-event';
test('should mark the first checkbox as checked', () => {
// render the grocery list
render(<GroceryList />);
// grab the apple item
const appleItem = screen.getByLabelText('Apples');
// simulate a "click" on the apple checkbox
userEvent.click(appleItem);
// assert that the apple checkbox was checked
expect(appleItem).toBeChecked();
});
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter