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: incorporate eslint-plugin-testing-library and fix reported issues #992

Merged
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
2 changes: 2 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"react-hooks",
"import",
"vitest",
"testing-library",
"eslint-plugin-react-compiler"
],
"parser": "@typescript-eslint/parser",
Expand Down Expand Up @@ -109,6 +110,7 @@
},
"overrides": [
{
"extends": ["plugin:testing-library/react"],
"files": ["tests/**/*.ts", "tests/**/*.tsx"],
"rules": {
"import/extensions": ["error", "never"],
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
"eslint-plugin-react": "^7.37.2",
"eslint-plugin-react-compiler": "19.0.0-beta-8a03594-20241020",
"eslint-plugin-react-hooks": "^5.0.0",
"eslint-plugin-testing-library": "^6.4.0",
"eslint-plugin-vitest": "^0.5.4",
"jest-leak-detector": "^29.7.0",
"jsdom": "^25.0.1",
Expand Down
92 changes: 92 additions & 0 deletions pnpm-lock.yaml

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

12 changes: 6 additions & 6 deletions tests/basic.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -516,16 +516,16 @@ it('stable snapshot object (#985)', async () => {
)
}

const { getByText, findByText } = render(<TestComponent />)
render(<TestComponent />)

await findByText('count: 0')
await screen.findByText('count: 0')
expect(effectCount).toBe(1)

fireEvent.click(getByText('button'))
await findByText('count: 1')
fireEvent.click(screen.getByText('button'))
await screen.findByText('count: 1')
expect(effectCount).toBe(1)

fireEvent.click(getByText('button'))
await findByText('count: 2')
fireEvent.click(screen.getByText('button'))
await screen.findByText('count: 2')
expect(effectCount).toBe(1)
})
25 changes: 10 additions & 15 deletions tests/proxySet.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -641,16 +641,15 @@ describe('ui updates - useSnapshot', async () => {
)
}

const { getByText } = render(
render(
<StrictMode>
<TestComponent />
</StrictMode>,
)

fireEvent.click(getByText('Add Item'))
await waitFor(() => {
getByText('1')
})
fireEvent.click(screen.getByText('Add Item'))

expect(await screen.findByText('1')).toBeDefined()
})

it('should be reactive to changes when using keys method', async () => {
Expand All @@ -676,16 +675,14 @@ describe('ui updates - useSnapshot', async () => {
)
}

const { getByText } = render(
render(
<StrictMode>
<TestComponent />
</StrictMode>,
)

fireEvent.click(getByText('Add Item'))
await waitFor(() => {
getByText('item key: 1')
})
fireEvent.click(screen.getByText('Add Item'))
expect(await screen.findByText('item key: 1')).toBeDefined()
})

it('should be reactive to changes when using entries method', async () => {
Expand All @@ -711,16 +708,14 @@ describe('ui updates - useSnapshot', async () => {
)
}

const { getByText } = render(
render(
<StrictMode>
<TestComponent />
</StrictMode>,
)

fireEvent.click(getByText('Add Item'))
await waitFor(() => {
getByText('key: 1; value: 1')
})
fireEvent.click(screen.getByText('Add Item'))
expect(await screen.findByText('key: 1; value: 1')).toBeDefined()
})
})

Expand Down
4 changes: 0 additions & 4 deletions tests/setup.ts

This file was deleted.

4 changes: 3 additions & 1 deletion vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ export default defineConfig({
},
test: {
name: 'valtio',
setupFiles: './tests/setup.ts',
// Keeping globals to true triggers React Testing Library's auto cleanup
// https://vitest.dev/guide/migration.html
globals: true,
coverage: {
include: ['src/**/'],
reporter: ['text', 'json', 'html', 'text-summary'],
Expand Down