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 #997

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",
"jest-dom",
"testing-library",
"eslint-plugin-react-compiler"
],
Expand Down Expand Up @@ -107,6 +108,7 @@
"overrides": [
{
"extends": [
"plugin:jest-dom/recommended",
"plugin:testing-library/react",
"plugin:@vitest/legacy-recommended"
],
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/test-old-typescript.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ jobs:
if: ${{ startsWith(matrix.typescript, '4.') || startsWith(matrix.typescript, '3.') }}
run: |
sed -i~ 's/"verbatimModuleSyntax": true,//' tsconfig.json
sed -i~ 's/"lib": \["es2023"\],//' tsconfig.json
- name: Patch for Old TS
run: |
sed -i~ 's/"moduleResolution": "bundler",/"moduleResolution": "node",/' tsconfig.json
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
"@rollup/plugin-node-resolve": "^15.3.0",
"@rollup/plugin-replace": "^6.0.1",
"@rollup/plugin-typescript": "^12.1.1",
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.0.1",
"@types/jsdom": "^21.1.7",
"@types/react": "^18.3.12",
Expand All @@ -125,6 +126,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-8a03594-20241020",
Expand Down
80 changes: 80 additions & 0 deletions pnpm-lock.yaml

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

6 changes: 3 additions & 3 deletions tests/proxySet.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ describe('ui updates - useSnapshot', async () => {

fireEvent.click(screen.getByText('Add Item'))

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

it('should be reactive to changes when using keys method', async () => {
Expand Down Expand Up @@ -682,7 +682,7 @@ describe('ui updates - useSnapshot', async () => {
)

fireEvent.click(screen.getByText('Add Item'))
expect(await screen.findByText('item key: 1')).toBeDefined()
expect(await screen.findByText('item key: 1')).toBeInTheDocument()
})

it('should be reactive to changes when using entries method', async () => {
Expand Down Expand Up @@ -715,7 +715,7 @@ describe('ui updates - useSnapshot', async () => {
)

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

Expand Down
1 change: 1 addition & 0 deletions tests/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '@testing-library/jest-dom/vitest'
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"compilerOptions": {
"target": "esnext",
"strict": true,
"lib": ["es2023"],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This line seems to be problematic with my changes and old TS versions. Zustand supports the same range of TypeScript versions but lacks this line. Maybe it can be safely removed?

Copy link
Member

Choose a reason for hiding this comment

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

It's added in #930. I think it's related to } catch { change.
If omitting this line goes well, I think it's fine to remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seems like using "lib": ["dom"] satisfies all TS versions.

"lib": ["dom"],
"jsx": "react-jsx",
"esModuleInterop": true,
"module": "esnext",
Expand All @@ -14,6 +14,7 @@
"verbatimModuleSyntax": true,
"declaration": true,
"isolatedDeclarations": true,
"types": ["@testing-library/jest-dom"],
"noEmit": true,
"baseUrl": ".",
"paths": {
Expand Down
1 change: 1 addition & 0 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default defineConfig({
// Keeping globals to true triggers React Testing Library's auto cleanup
// https://vitest.dev/guide/migration.html
globals: true,
setupFiles: ['tests/setup.ts'],
coverage: {
include: ['src/**/'],
reporter: ['text', 'json', 'html', 'text-summary'],
Expand Down