Skip to content

Commit

Permalink
test: ✅ use userEvent v14 api instead of v13
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmy-guzman committed Apr 26, 2023
1 parent a913997 commit e9d4e4f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/App.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import App from './App'
import { render, userEvent, screen } from './test/utils'
import { render, screen } from './test/utils'

describe('app', () => {
it('should increase count', async () => {
render(<App />)
const { user } = render(<App />)

userEvent.click(screen.getByRole('button', { name: /count is 0/i }))
user.click(screen.getByRole('button', { name: /count is 0/i }))

await expect(
screen.findByRole('button', { name: /count is 1/i })
Expand Down
18 changes: 0 additions & 18 deletions src/test/utils.ts

This file was deleted.

20 changes: 20 additions & 0 deletions src/test/utils.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { cleanup, render } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { afterEach } from 'vitest'

afterEach(() => {
cleanup()
})

const customRender = (ui: React.ReactElement, options = {}) => {
return {
user: userEvent.setup(),
...render(ui, {
wrapper: ({ children }) => children,
...options,
}),
}
}

export * from '@testing-library/react'
export { customRender as render }

1 comment on commit e9d4e4f

@vercel
Copy link

@vercel vercel bot commented on e9d4e4f Apr 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.