Skip to content

Instantly share code, notes, and snippets.

@BrianJenney
Last active September 21, 2020 19:32
Show Gist options
  • Save BrianJenney/98fd1f2f951eb638e43410a3cacaa768 to your computer and use it in GitHub Desktop.
Save BrianJenney/98fd1f2f951eb638e43410a3cacaa768 to your computer and use it in GitHub Desktop.
const ProductDetail = () => {
const classes = useStyles();
const cart = useSelector(state => state.cart);
const { product } = useContext(ProductContext);
return (
<Card >
<CardContent>
<Box>
{product.name}: {cart.count}
</Box>
</CardContent>
</Card>
);
}
import React from 'react';
import '../../../test/setup';
import { cleanup, fireEvent, findByText } from '@testing-library/react';
import ProductDetail from './ProductDetail';
describe('Product Details', () => {
afterEach(() => {
cleanup();
});
it('renders with default data', async () => {
const { queryByText, getByTestId } = render(
<ProductDetail product={{name: 'Cool Product'}} cart={{count: 1}} />
);
expect(queryByText('Cool Product: 1')).toBeTruthy();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment