Skip to content

Commit

Permalink
test: add jest-dom matchers and eslint plugin (#997)
Browse files Browse the repository at this point in the history
  • Loading branch information
kretajak authored Nov 13, 2024
1 parent e65fd89 commit f3cbd01
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 5 deletions.
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"],
"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

0 comments on commit f3cbd01

Please sign in to comment.