Skip to content

Instantly share code, notes, and snippets.

@a-luna
Last active January 2, 2022 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a-luna/cc2616b97eadabe050a87d6bb68d0e5c to your computer and use it in GitHub Desktop.
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.
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
module.exports = {
presets: [['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-typescript'],
};
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;
import '@testing-library/jest-dom';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment