Skip to content

Instantly share code, notes, and snippets.

@git2thehub
Created February 8, 2023 19:46
Show Gist options
  • Save git2thehub/dabbd4d0233d62d429f35e9851e56cb4 to your computer and use it in GitHub Desktop.
Save git2thehub/dabbd4d0233d62d429f35e9851e56cb4 to your computer and use it in GitHub Desktop.
test file
import App from './App'
import { shallow } from 'enzyme'
// Test 1: Write a test that checks to see if our `App` component renders without throwing an error.
it('App Component Renders Without Error', () => {
const wrapper = shallow(<App />)
})
// Test 2: Write a test that checks if the button within the `App` component renders properly.
it("App Component Renders a Button", () => {
const wrapper = shallow(<App />)
const button = wrapper.find('[data-test="increment-button"]')
expect(button.length).toBe(1)
})
// Test 3: Write a test which checks if the counter starts at 0.
it("Counter Starts At 0", () => {
const wrapper = shallow(<App />)
const count = wrapper.find('[data-test="count"]').text()
expect(count).toBe("0")
})
// Test 4: Write a test which checks if the increment button increase the count.
it("Clicking Increment Button Increases Counter Display", () => {
const wrapper = shallow(<App />)
const button = wrapper.find('[data-test="increment-button"]')
button.simulate('click')
const count = wrapper.find('[data-test="count"]').text()
expect(count).toBe('1')
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment