Skip to content

Commit

Permalink
[client-svelte] Test env fixes
Browse files Browse the repository at this point in the history
Configure @testing-library/jest-dom correctly to
resolve the type definitions in the test files,
even the plugin is extended in a global setup file.

The Svelte component's onMount hooks right now executed
properly. Unfortunately vitest running in node but Svelte
render's the components in SSR mode, so the onMount callbacks
didn't executed in tests. An ugly workaround was needed to
solve this:

vitest-dev/vitest#2834 (comment)
  • Loading branch information
samson84 committed Dec 30, 2023
1 parent 75b718d commit 2295737
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 4 deletions.
1 change: 0 additions & 1 deletion client-svelte/src/lib/DisplayTodoItem.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import '@testing-library/jest-dom'
import { describe, it, expect, afterEach, vi } from 'vitest'
import { render, fireEvent, screen } from '@testing-library/svelte'

Expand Down
1 change: 1 addition & 0 deletions client-svelte/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"allowJs": true,
"checkJs": true,
"isolatedModules": true,
"types": ["@testing-library/jest-dom"]
},
"include": ["src/**/*.ts", "src/**/*.js", "src/**/*.svelte"],
"references": [{ "path": "./tsconfig.node.json" }]
Expand Down
1 change: 0 additions & 1 deletion client-svelte/tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"types": ["vitest/global"]
},
"include": ["vite.config.ts"]
}
2 changes: 1 addition & 1 deletion client-svelte/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ export default defineConfig({
proxy: {
'/api': 'http://localhost:4400'
}
}
},
})
4 changes: 3 additions & 1 deletion client-svelte/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ export default defineConfig({
test: {
globals: true,
environment: 'jsdom',
},
alias: [{ find: /^svelte$/, replacement: 'svelte/internal' }],
setupFiles: ['./vitest-setup.ts']
}
})

0 comments on commit 2295737

Please sign in to comment.