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: add jest-dom matchers and eslint plugin #2808

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"import",
"@vitest",
"eslint-plugin-react-compiler",
"jest-dom",
"testing-library"
],
"parser": "@typescript-eslint/parser",
Expand Down Expand Up @@ -107,6 +108,7 @@
"overrides": [
{
"extends": [
"plugin:jest-dom/recommended",
"plugin:testing-library/react",
"plugin:@vitest/legacy-recommended"
],
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/test-old-typescript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ jobs:
if: ${{ matrix.typescript == '4.4.4' || matrix.typescript == '4.3.5' || matrix.typescript == '4.2.3' || matrix.typescript == '4.1.5' || matrix.typescript == '4.0.5' || startsWith(matrix.typescript, '3.') }}
run: |
pnpm add -D [email protected] @vitest/[email protected] @vitest/[email protected]
pnpm add -D @testing-library/jest-dom@5 @types/testing-library__jest-dom@5
pnpm add -D @types/[email protected]
sed -i~ 's/"@testing-library\/jest-dom"/"@types\/testing-library__jest-dom"/' tsconfig.json

dai-shi marked this conversation as resolved.
Show resolved Hide resolved
- name: Patch testing setup for older TS
if: ${{ matrix.typescript == '4.0.5' || startsWith(matrix.typescript, '3.') }}
run: |
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^12.1.1",
"@testing-library/dom": "^10.4.0",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.0.1",
"@testing-library/user-event": "^14.5.2",
"@types/babel__core": "^7.20.5",
Expand All @@ -147,6 +148,7 @@
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-alias": "^1.1.2",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-jest-dom": "^5.4.0",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react-compiler": "19.0.0-beta-a7bf2bd-20241110",
Expand Down
85 changes: 85 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 1 addition & 8 deletions tests/react/async.test.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import { StrictMode, Suspense, useEffect, useRef } from 'react'
import {
act,
fireEvent,
render,
screen,
waitFor,
waitForElementToBeRemoved,
} from '@testing-library/react'
import { act, fireEvent, render, screen, waitFor } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { expect, it } from 'vitest'
import { useAtom } from 'jotai/react'
Expand Down
24 changes: 12 additions & 12 deletions tests/react/optimization.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,24 @@ it('only relevant render function called (#156)', async () => {
</>,
)

expect(screen.getByText('count1: 0')).toBeDefined()
expect(screen.getByText('count2: 0')).toBeDefined()
expect(screen.getByText('count1: 0')).toBeInTheDocument()
expect(screen.getByText('count2: 0')).toBeInTheDocument()

const viewCount1AfterMount = viewCount1
const viewCount2AfterMount = viewCount2

await userEvent.click(screen.getByText('button1'))

expect(screen.getByText('count1: 1')).toBeDefined()
expect(screen.getByText('count2: 0')).toBeDefined()
expect(screen.getByText('count1: 1')).toBeInTheDocument()
expect(screen.getByText('count2: 0')).toBeInTheDocument()

expect(viewCount1).toBe(viewCount1AfterMount + 1)
expect(viewCount2).toBe(viewCount2AfterMount + 0)

await userEvent.click(screen.getByText('button2'))

expect(screen.getByText('count1: 1')).toBeDefined()
expect(screen.getByText('count2: 1')).toBeDefined()
expect(screen.getByText('count1: 1')).toBeInTheDocument()
expect(screen.getByText('count2: 1')).toBeInTheDocument()

expect(viewCount1).toBe(viewCount1AfterMount + 1)
expect(viewCount2).toBe(viewCount2AfterMount + 1)
Expand Down Expand Up @@ -252,21 +252,21 @@ it('no extra rerenders after commit with derived atoms (#1213)', async () => {

await userEvent.click(screen.getByText('inc1'))

expect(screen.getByText('count1: 1')).toBeDefined()
expect(screen.getByText('count2: 0')).toBeDefined()
expect(screen.getByText('count1: 1')).toBeInTheDocument()
expect(screen.getByText('count2: 0')).toBeInTheDocument()

expect(viewCount1).toBe(viewCount1AfterCommit)

await userEvent.click(screen.getByText('inc2'))

expect(screen.getByText('count1: 1')).toBeDefined()
expect(screen.getByText('count2: 1')).toBeDefined()
expect(screen.getByText('count1: 1')).toBeInTheDocument()
expect(screen.getByText('count2: 1')).toBeInTheDocument()

expect(viewCount2).toBe(viewCount2AfterCommit)

await userEvent.click(screen.getByText('inc1'))

expect(screen.getByText('count1: 2')).toBeDefined()
expect(screen.getByText('count2: 1')).toBeDefined()
expect(screen.getByText('count1: 2')).toBeInTheDocument()
expect(screen.getByText('count2: 1')).toBeInTheDocument()
expect(viewCount1).toBe(viewCount1AfterCommit)
})
4 changes: 2 additions & 2 deletions tests/react/vanilla-utils/atomWithDefault.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ it('can be set synchronously by passing value', async () => {

render(<Counter />)

expect(screen.getByText('count: 1')).toBeDefined()
expect(screen.getByText('count: 1')).toBeInTheDocument()

await userEvent.click(screen.getByRole('button', { name: 'Set to 10' }))

expect(screen.getByText('count: 10')).toBeDefined()
expect(screen.getByText('count: 10')).toBeInTheDocument()
})
4 changes: 2 additions & 2 deletions tests/react/vanilla-utils/atomWithStorage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -545,9 +545,9 @@ describe('atomWithStorage (with browser storage)', () => {
expect(store.get(isLoggedAtom)).toBeTruthy()
expect(store.get(isDevModeStorageAtom)).toBeTruthy()

expect(checkbox.checked).toBeTruthy()
expect(checkbox).toBeChecked()
await userEvent.click(checkbox)
expect(checkbox.checked).toBeFalsy()
expect(checkbox).not.toBeChecked()
})
})

Expand Down
Loading