简体   繁体   English

使用Angular-CLI使用Karma和Jasmine设置进行ng测试时出现许多错误

[英]So many errors on ng test with Karma and Jasmine setup using Angular-CLI

Getting these errors on running the ng test command. 在运行ng test命令时遇到这些错误。 I have created this project using Angular-Cli. 我已经使用Angular-Cli创建了这个项目。 Ng serve is working fine without any error but ng test not running properly. NG服务正常,没有任何错误,但是ng测试无法正常运行。

ERROR in D:/Working/TestAngular4/node_modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.d.ts (32,16): Cannot find name 'M
    ap'.
ERROR in D:/Working/TestAngular4/node_modules/@angular/core/src/di/reflective_provider.d.ts (87,123): Cannot find name 'Map'.

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

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

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

    ERROR in D:/Working/TestAngular4/node_modules/@angular/core/src/change_detection/differs/default_iterable_differ.d.ts (28,32): Cannot find name 'I
    terable'.

    ERROR in D:/Working/TestAngular4/node_modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.d.ts (24,16): Cannot find name 'M
    ap'.

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

    ERROR in D:/Working/TestAngular4/node_modules/@angular/common/src/directives/ng_class.d.ts (48,34): Cannot find name 'Set'.

    ERROR in D:/Working/TestAngular4/node_modules/@angular/router/src/router_outlet_context.d.ts (42,28): Cannot find name 'Map'.

    ERROR in D:/Working/TestAngular4/node_modules/@angular/router/src/router_outlet_context.d.ts (43,34): Cannot find name 'Map'.

    ERROR in D:/Working/TestAngular4/node_modules/rxjs/operator/toPromise.d.ts (3,79): 'Promise' only refers to a type, but is being used as a value h
    ere.

    ERROR in D:/Working/TestAngular4/node_modules/@angular/http/src/headers.d.ts (52,71): Cannot find name 'Map'.

    ERROR in D:/Working/TestAngular4/node_modules/@angular/http/src/url_search_params.d.ts (46,16): Cannot find name 'Map'.

    Even I changes the auto created target ES5 to ES6.

Below is my tsconfig.json 以下是我的tsconfig.json

    {
    "compileOnSave": false,
    "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "skipLibCheck": true,
    "target": "es6",
    "typeRoots": [
    "node_modules/@types"
    ],
    "lib": [
    "es2017",
    "dom"
    ]
    }
    }

and below is Package.json 下面是Package.json

    {
    "name": "ccw-client-app",
    "version": "0.0.0",
    "license": "Copyright, 2017",
    "scripts": {
    "ng": "ng",
    "start-ng": "ng serve",
    "start": "node src/server/index.js",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "sme": "./node_modules/.bin/source-map-explorer"
    },
    "private": true,
    "dependencies": {
    "@angular/animations": "^4.3.6",
    "@angular/cdk": "^2.0.0-beta.10",
    "@angular/common": "^4.3.6",
    "@angular/compiler": "^4.3.6",
    "@angular/core": "^4.3.6",
    "@angular/flex-layout": "^2.0.0-beta.9",
    "@angular/forms": "^4.3.6",
    "@angular/http": "^4.3.6",
    "@angular/material": "^2.0.0-beta.10",
    "@angular/platform-browser": "^4.3.6",
    "@angular/platform-browser-dynamic": "^4.3.6",
    "@angular/router": "^4.3.6",
    "": "^4.0.3",
    "": "^7.2.0",
    "": "^1.0.2",
    "angular2-logger": "^0.6.0",
    "core-js": "^2.4.1",
    "devextreme": "^17.1.6",
    "devextreme-angular": "^17.1.6",
    "hammerjs": "^2.0.8",
    "rxjs": "^5.4.2",
    "zone.js": "^0.8.14"
    },
    "devDependencies": {
    "@angular/cli": "^1.3.2",
    "@angular/compiler-cli": "^4.3.6",
    "@angular/language-service": "^4.3.6",
    "": "^4.0.0",
    "": "~2.5.53",
    "": "~2.0.2",
    "": "~6.0.60",
    "codelyzer": "~3.1.1",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "karma-junit-reporter": "^1.2.0",
    "karma-phantomjs-launcher": "^1.0.4",
    "phantomjs-prebuilt": "^2.1.15",
    "protractor": "~5.1.2",
    "source-map-explorer": "^1.4.0",
    "ts-node": "~3.2.0",
    "tslint": "~5.3.2",
    "typescript": "~2.3.3"
    }
    }


Please help.

尝试将tsconfig中的目标属性更改为ES5

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM