Last active
January 2, 2022 20:48
-
-
Save a-luna/cc2616b97eadabe050a87d6bb68d0e5c to your computer and use it in GitHub Desktop.
Whenever I start a new project, I need to figure out exactly which packages are required for testing svelte components with jest. I am documenting the list of packages and required config files here to avoid repeating this in the future.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm i -D @babel/core @babel/preset-env @babel/preset-typescript @testing-library/jest-dom @testing-library/svelte @types/jest @types/node @types/testing-library__jest-dom babel-jest jest svelte-jester ts-jest ts-node typescript |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
presets: [['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-typescript'], | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const config = { | |
roots: ['<rootDir>/src'], | |
preset: 'ts-jest', | |
testEnvironment: 'jsdom', | |
collectCoverage: true, | |
coverageDirectory: 'coverage', | |
testPathIgnorePatterns: ['/node_modules/'], | |
setupFilesAfterEnv: ['<rootDir>/src/lib/__tests__/setup/jestSetup.ts'], | |
bail: false, | |
verbose: true, | |
transform: { | |
'^.+\\.svelte$': [ | |
'svelte-jester', | |
{ | |
preprocess: true | |
} | |
], | |
'.(ts|tsx)': 'ts-jest' | |
}, | |
testRegex: '(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$', | |
moduleFileExtensions: ['ts', 'tsx', 'js', 'svelte'], | |
moduleNameMapper: { | |
'^\\$lib(.*)$': '<rootDir>/src/lib$1', | |
'^\\$app(.*)$': [ | |
'<rootDir>/.svelte-kit/dev/runtime/app$1', | |
'<rootDir>/.svelte-kit/build/runtime/app$1' | |
] | |
} | |
}; | |
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import '@testing-library/jest-dom'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment