Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: use screen exposed by React Testing Library #2787

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions tests/react/abortable.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { StrictMode, Suspense, useState } from 'react'
import { render, waitFor } from '@testing-library/react'
import { render, screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { describe, expect, it } from 'vitest'
import { useAtomValue, useSetAtom } from 'jotai/react'
Expand Down Expand Up @@ -33,7 +33,7 @@ describe('abortable atom test', () => {
)
}

const { findByText, getByText } = render(
render(
<StrictMode>
<Suspense fallback="loading">
<Component />
Expand All @@ -42,22 +42,22 @@ describe('abortable atom test', () => {
</StrictMode>,
)

await findByText('loading')
await screen.findByText('loading')

resolve.splice(0).forEach((fn) => fn())
await findByText('count: 0')
await screen.findByText('count: 0')
expect(abortedCount).toBe(0)

await userEvent.click(getByText('button'))
await userEvent.click(getByText('button'))
await userEvent.click(screen.getByText('button'))
await userEvent.click(screen.getByText('button'))
resolve.splice(0).forEach((fn) => fn())
await findByText('count: 2')
await screen.findByText('count: 2')

expect(abortedCount).toBe(1)

await userEvent.click(getByText('button'))
await userEvent.click(screen.getByText('button'))
resolve.splice(0).forEach((fn) => fn())
await findByText('count: 3')
await screen.findByText('count: 3')
expect(abortedCount).toBe(1)
})

Expand Down Expand Up @@ -90,7 +90,7 @@ describe('abortable atom test', () => {
)
}

const { findByText, getByText } = render(
render(
<StrictMode>
<Suspense fallback="loading">
<Component />
Expand All @@ -99,22 +99,22 @@ describe('abortable atom test', () => {
</StrictMode>,
)

await findByText('loading')
await screen.findByText('loading')
resolve.splice(0).forEach((fn) => fn())
await findByText('count: 0')
await screen.findByText('count: 0')

expect(abortedCount).toBe(0)

await userEvent.click(getByText('button'))
await userEvent.click(getByText('button'))
await userEvent.click(screen.getByText('button'))
await userEvent.click(screen.getByText('button'))
resolve.splice(0).forEach((fn) => fn())
await findByText('count: 2')
await screen.findByText('count: 2')

expect(abortedCount).toBe(1)

await userEvent.click(getByText('button'))
await userEvent.click(screen.getByText('button'))
resolve.splice(0).forEach((fn) => fn())
await findByText('count: 3')
await screen.findByText('count: 3')

expect(abortedCount).toBe(1)
})
Expand Down Expand Up @@ -149,24 +149,24 @@ describe('abortable atom test', () => {
)
}

const { findByText, getByText } = render(
render(
<StrictMode>
<Suspense fallback="loading">
<Parent />
</Suspense>
</StrictMode>,
)

await findByText('loading')
await screen.findByText('loading')

resolve.splice(0).forEach((fn) => fn())
await findByText('count: 0')
await screen.findByText('count: 0')
expect(abortedCount).toBe(0)

await userEvent.click(getByText('button'))
await userEvent.click(getByText('toggle'))
await userEvent.click(screen.getByText('button'))
await userEvent.click(screen.getByText('toggle'))

await findByText('hidden')
await screen.findByText('hidden')

resolve.splice(0).forEach((fn) => fn())
await waitFor(() => expect(abortedCount).toBe(0))
Expand Down Expand Up @@ -198,7 +198,7 @@ describe('abortable atom test', () => {
)
}

const { findByText, getByText } = render(
render(
<StrictMode>
<Suspense fallback="loading">
<Component />
Expand All @@ -207,18 +207,18 @@ describe('abortable atom test', () => {
</StrictMode>,
)

await findByText('loading')
await screen.findByText('loading')

resolve.splice(0).forEach((fn) => fn())
await findByText('count: 0')
await screen.findByText('count: 0')

await userEvent.click(getByText('button'))
await userEvent.click(getByText('button'))
await userEvent.click(screen.getByText('button'))
await userEvent.click(screen.getByText('button'))
resolve.splice(0).forEach((fn) => fn())
await findByText('count: 2')
await screen.findByText('count: 2')

await userEvent.click(getByText('button'))
await userEvent.click(screen.getByText('button'))
resolve.splice(0).forEach((fn) => fn())
await findByText('count: 3')
await screen.findByText('count: 3')
})
})
Loading