Skip to content

Instantly share code, notes, and snippets.

@minademian
Last active September 23, 2021 05:37
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 minademian/9efb9cfc3494ae619877a85946337eda to your computer and use it in GitHub Desktop.
Save minademian/9efb9cfc3494ae619877a85946337eda to your computer and use it in GitHub Desktop.
Configuring Jest with Angular 10+
package.json
"jest": {
"testEnvironment": "jsdom"
}
install latest version of Jest
"test": "ng test",
"test-watch": "ng test --watch",
jest.config.js
// https://github.com/thymikee/jest-preset-angular#brief-explanation-of-config
module.exports = {
preset: 'jest-preset-angular',
roots: ['src'],
moduleNameMapper: {
'@app/(.*)': '<rootDir>/src/app/$1',
'@assets/(.*)': '<rootDir>/src/assets/$1',
'@core/(.*)': '<rootDir>/src/app/core/$1',
'@env': '<rootDir>/src/environments/environment',
'@src/(.*)': '<rootDir>/src/$1',
'@state/(.*)': '<rootDir>/src/app/state/$1'
},
transformIgnorePatterns: ['node_modules/(?!(jest-test))'],
testMatch: [
"**/*.spec.ts"
],
globals: {
'ts-jest': {
diagnostics: false,
tsconfig: '<rootDir>/tsconfig.spec.json'
}
}
};
angular.json
"test": {
"builder": "@angular-builders/jest:run"
},
tsconfig.json
"types": ["jest"],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment