在ng测试命令上获得错误(KARMA - JASMINE单元测试)

时间:2018-04-04 07:40:15

标签: angular unit-testing typescript angular-cli karma-jasmine

在我的应用程序中,我正在整合Angular cli,因为它首先不存在!

我想用karma和jasmine来测试我的应用程序。

当我运行命令ng test时,我收到错误:

package.json

@angular/cli: 1.1.0
node: 7.10.1
os: linux x64
@angular/animations: 4.4.6
@angular/common: 4.4.6
@angular/compiler: 4.4.6
@angular/core: 4.4.6
@angular/forms: 4.4.6
@angular/http: 4.4.6
@angular/platform-browser: 4.4.6
@angular/platform-browser-dynamic: 4.4.6
@angular/router: 4.4.6
@angular/service-worker: 1.0.0-beta.16
@angular/cli: 1.1.0
@angular/compiler-cli: 4.4.6
@angular/language-service: 4.4.6
@angular/platform-server: 4.4.6

观察到的行为

ERROR in /repo/node_modules/@angular/core/src/di/reflective_provider.d.ts (87,123): Cannot find name 'Map'.

ERROR in /repo/node_modules/@angular/core/src/di/reflective_provider.d.ts (87,165): Cannot find name 'Map'.

ERROR in /repo/node_modules/rxjs/Observable.d.ts (58,60): 'Promise' only refers to a type, but is being used as a value here.

ERROR in /repo/node_modules/rxjs/Observable.d.ts (73,59): 'Promise' only refers to a type, but is being used as a value here.

ERROR in /repo/node_modules/@angular/core/src/change_detection/differs/iterable_differs.d.ts (15,48): Cannot find name 'Iterable'.

ERROR in /repo/node_modules/@angular/core/src/change_detection/differs/keyvalue_differs.d.ts (23,18): Cannot find name 'Map'.

ERROR in /repo/node_modules/@angular/core/src/change_detection/differs/default_iterable_differ.d.ts (28,32): Cannot find name 'Iterable'.

ERROR in /repo/node_modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.d.ts (24,16): Cannot find name 'Map'.

ERROR in /repo/node_modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.d.ts (32,16): Cannot find name 'Map'.

ERROR in /repo/src/client/app/iterm-extended/component/get-a-quote.component.ts (32,14): Experimental support for decorators is a feature that is subject to change in a future release. Set the 'experimentalDecorators' option to remove this warning.

期望的行为

我想在浏览器上看到 UNIT TESTING

由于这些错误,我无法进行测试。

即使在StackOverflow上,我也没有找到与这些错误相关的任何内容。

tsconfig.json

{
  "compilerOptions": {
    // "module": "es2015",
    "moduleResolution": "node",
    "target": "es5",
    "noImplicitAny": false,
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "es2017",
      "dom"
    ],
    "typeRoots": [
      "node_modules/@types"
    ],
    "skipLibCheck": true
  },
  "include": [
    "src/client/**/*.ts"
  ],
  "exclude": [
    "node_modules",
    "src/client/main-prod.ts"
  ],
  "compileOnSave": false
}

karma.config.js

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular/cli'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular/cli/plugins/karma')
    ],
    files: [
      "src/client/test-cases/iterm-extended/**/*.spec.ts",
      { pattern: 'node_modules/**', included: false, watched: false },
      { pattern: 'src/client/app/iinvest/**', included: false, watched: false },
      { pattern: 'src/client/app/imax/**', included: false, watched: false },
      { pattern: 'src/client/app/iterm/**', included: false, watched: false },
      { pattern: 'src/client/app/itermPlus-extended/**', included: false, watched: false },
      { pattern: 'src/client/app/pages/**', included: false, watched: false },
      { pattern: 'src/client/app/shared/**', included: false, watched: false }
    ],
    client: {
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      reports: ['html', 'lcovonly'],
      fixWebpackSourcePaths: true
    },
    angularCli: {
      environment: 'dev'
    },
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
    browsers: ['Chrome'],
    singleRun: false
  });
};

0 个答案:

没有答案