Skip to content

Instantly share code, notes, and snippets.

@git2thehub
Created February 7, 2024 15:49
Show Gist options
  • Save git2thehub/b832484ef1cc80abe0e27e0c8b2849b1 to your computer and use it in GitHub Desktop.
Save git2thehub/b832484ef1cc80abe0e27e0c8b2849b1 to your computer and use it in GitHub Desktop.
Help you get started refactoring code
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import App from '../App';
const renderApp = () => {
render(<App />);
return {
getIncrementBtn: () => screen.getByRole('button', { name: 'increment counter' }),
getDecrementBtn: () => screen.getByRole('button', { name: 'decrement counter' }),
getErrorHeading: () => screen.getByRole('heading', { level: 2 }),
getCountAtZero: () => screen.getByText('0'),
getCountAtOne: () => screen.getByText('1'),
};
}
// Test 1: Write a test that checks to see if our `App` component renders without throwing an error.
it('App Component Renders Without Error', () => {
renderApp();
});
// Test 2: Write a test that checks if the button within the `App` component renders properly.
it('App Component Renders a Button', () => {
const { getIncrementBtn } = renderApp();
const button = getIncrementBtn();
expect(button).toBeDefined();
});
// rest of code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment