Angular项目Jest配置的预设 - jest-preset-angular

2017-03-31      39      JavaScript
项目简介

jest-preset-angular

Angular项目Jest配置的预设。

使用方法

在src目录,创建setupJest.ts文件,添加系列内容:

import 'jest-preset-angular';
import './jestGlobalMocks'; // browser mocks globally available for every test

然后在package.json中加入:

"jest": {
  "preset": "jest-preset-angular",
  "setupTestFrameworkScriptFile": "<rootDir>/src/setupJest.ts"
}

配置

{
  "globals": {
    "__TS_CONFIG__": "src/tsconfig.spec.json",
    "__TRANSFORM_HTML__": true
  },
  "transform": {
    "^.+\\.(ts|js|html)$": "<rootDir>/node_modules/jest-preset-angular/preprocessor.js"
  },
  "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|js)$",
  "moduleFileExtensions": [
    "ts",
    "js",
    "html"
  ],
  "moduleNameMapper": {
    "app/(.*)": "<rootDir>/src/app/$1",
    "environments/(.*)": "<rootDir>/src/environments/$1"
  },
  "transformIgnorePatterns": [
    "node_modules/(?!@ngrx)"
  ]
}