Created
July 6, 2021 06:00
-
-
Save manoj-mass/86d71c5f8c3d64a6d805f0e572d5421f to your computer and use it in GitHub Desktop.
Counter spec file https://medium.com/@manojdarshana/reactjs-testing-with-jest-81bb17dd6c65
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { render, screen } from '@testing-library/react'; | |
import userEvent from '@testing-library/user-event'; | |
import Counter from './Counter'; | |
const setUp = () => render(<Counter />); | |
beforeEach(() => { | |
setUp() | |
}) | |
describe('test counter app', () => { | |
it('check h1 available', () => { | |
const linkElement = screen.getByText(/Current count is/i); | |
expect(linkElement).toBeInTheDocument(); | |
}); | |
it('check button available', () => { | |
const linkElement = screen.getByText(/Increment/i); | |
expect(linkElement).toBeInTheDocument(); | |
}); | |
it('check increment', () => { | |
userEvent.click(screen.getByText(/Increment/i)); | |
const lable = screen.getByTestId(/counterID/i); | |
expect(lable.textContent).toBe("1"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment