gpt4 book ai didi

javascript - 从8到9的 Angular 更新给测试框架带来了问题

转载 作者:行者123 更新时间:2023-12-03 12:38:46 27 4
gpt4 key购买 nike

我已经使用以下命令将应用程序从Angular 8升级到了9
ng update @ angular/core @ 9 @ angular/cli @ 9
根据以下指南https://update.angular.io/?l=2&v=8.1-9.0
迁移成功,但是当我“服务”时,多个.spec文件中出现错误
从下面的命令行添加一些错误和建议

1) test.component.spec.ts:395:13 - error TS2304: Cannot find name 'expect'.
395 expect(effects.loadTest$).toBeObservable(expected);

2) home.component.spec.ts:365:5 - error TS2593: Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig.

365 describe('myTest$', () => {
我正在使用Jasmin作为我的测试运行者,但是为什么会低于建议(我已经尝试过并且也没有用)
 Do you need to install type definitions for a test runner? Try `npm i @types/jest` or `npm i @types/mocha` and then add `jest` or `mocha` to the types field in your tsconfig.
请在Upgarde之后找到我的package.json
{
"name": "myapp",
"productName": "MyApp",
"description": "My Test App",
"version": "0.5.0",
"license": "",
"main": "main.js",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build --aot",
"build:prod": "ng build --prod",
"test": "ng test",
"test-ci": "ng test --watch=false --reporters junit --code-coverage --browsers HeadlessChrome --progress=false",
"coverage": "ng test --watch=false --code-coverage",
"lint": "ng lint",
"bundle-report": "webpack-bundle-analyzer dist/stats.json",
"electron-dev": "concurrently -k \"ng serve\" \"electron .\"",
"start:electron": "electron ."
},
"dependencies": {
"@angular/animations": "9.1.12",
"@angular/cdk": "~8.2.3",
"@angular/common": "9.1.12",
"@angular/compiler": "9.1.12",
"@angular/core": "9.1.12",
"@angular/forms": "9.1.12",
"@angular/material": "~8.2.3",
"@angular/platform-browser": "9.1.12",
"@angular/platform-browser-dynamic": "9.1.12",
"@angular/router": "9.1.12",
"@microsoft/signalr": "^3.1.8",
"@ngrx/effects": "^8.6.0",
"@ngrx/entity": "^8.6.0",
"@ngrx/router-store": "^8.6.0",
"@ngrx/store": "^8.6.0",
"@ngrx/store-devtools": "^8.6.0",
"@ngx-translate/core": "^12.1.2",
"@ngx-translate/http-loader": "^4.0.0",
"@types/file-saver": "^2.0.1",
"bootstrap": "^4.4.1",
"bootstrap-sass": "^3.4.1",
"browserslist": "^4.14.5",
"classlist.js": "^1.1.20150312",
"core-js": "^3.6.5",
"ej-angular2": "18.1.42",
"file-saver": "^2.0.2",
"hammerjs": "^2.0.8",
"istanbul-api": "^3.0.0",
"istanbul-reports": "^3.0.2",
"jasmine-marbles": "^0.6.0",
"jquery": "^3.4.1",
"js-yaml": "^3.13.1",
"kill-port": "^1.6.1",
"lodash": "^4.17.20",
"moment": "^2.29.0",
"ngx-bootstrap": "^5.6.2",
"ngx-image-cropper": "^0.2.9",
"node-sass": "^4.14.1",
"rxjs": "^6.6.3",
"syncfusion-javascript": "18.1.42",
"tslib": "^1.10.0",
"zone.js": "~0.10.2"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.901.12",
"@angular-devkit/core": "9.1.12",
"@angular-devkit/schematics": "9.1.12",
"@angular/cli": "^9.1.12",
"@angular/compiler-cli": "~9.1.12",
"@angular/language-service": "9.1.12",
"@ngrx/schematics": "^8.6.0",
"@types/bootstrap": "^3.4.0",
"@types/ej.web.all": "18.1.2",
"@types/fs-extra": "^8.1.1",
"@types/jasmine": "^3.5.14",
"@types/jasminewd2": "^2.0.8",
"@types/jquery": "3.5.0",
"@types/lodash": "^4.14.161",
"@types/node": "^12.11.1",
"angular-auth-oidc-client": "^9.0.8",
"codelyzer": "^5.1.2",
"electron": "^10.1.5",
"electron-builder": "^22.8.1",
"jasmine-core": "^3.6.0",
"jasmine-spec-reporter": "^6.0.0",
"karma": "^5.2.3",
"karma-chrome-launcher": "^3.1.0",
"karma-cli": "^2.0.0",
"karma-coverage-istanbul-reporter": "^3.0.2",
"karma-html-reporter": "^0.2.7",
"karma-jasmine": "^4.0.1",
"karma-jasmine-html-reporter": "^1.5.4",
"karma-junit-reporter": "^2.0.1",
"protractor": "^7.0.0",
"puppeteer": "^5.3.1",
"ts-node": "~8.10.1",
"tslint": "^6.1.3",
"typescript": "~3.8.3",
"webpack-bundle-analyzer": "^3.9.0"
}
}

最佳答案

您可能需要检查"typeRoots"tsconfig.json中的tsconfig.spec.json确保您具有以下条目:

 "typeRoots": ["node_modules/@types"],
如果您在 tsconfig.json中使用了它,也许 tsconfig.spec.json需要像这样扩展tsconfig.json:
  "extends": "../tsconfig.json",
同样,它可能无法解决问题,但是 packages.json中有一些依赖项可能需要像下面这样移入 devDependencies中:
"istanbul-api": "^3.0.0",
"istanbul-reports": "^3.0.2",
"jasmine-marbles": "^0.6.0",

关于javascript - 从8到9的 Angular 更新给测试框架带来了问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64762546/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com