gpt4 book ai didi

Angular 9 i18n迁移-测试失败

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

我正在从Angular 8.0升级到Angular 9.1.1。只需一点点工作,一切就可以构建并运行良好。
我遇到了本地化问题https://angular.io/guide/migration-localize,并按照以下说明进行操作-这使我的项目得以构建和运行!
但是,我在运行测试时仍然遇到此问题(因果/ Jasmine )

我使用CLI升级了我的项目。我似乎找不到其他任何必需的步骤来迁移本地化。

我正在使用TestBed进行单元测试,并且在调用TestBed.createComponent时失败,并抛出错误:

Error: It looks like your application or one of its dependencies is using i18n.
Angular 9 introduced a global `$localize()` function that needs to be loaded.
Please run `ng add @angular/localize` from the Angular CLI.
(For non-CLI projects, add `import '@angular/localize/init';` to your `polyfills.ts` file.
For server-side rendering applications add the import to your `main.server.ts` file.)


一个失败的测试组件模板中的HTML示例是:
<span i18n>
label
</span>

只需删除 i18n即可运行并通过测试-但这不是应用程序运行时的运行时错误。
关于下一步寻找什么或这里可能涉及到什么的任何线索?

我的 polypill.js的顶部
/***************************************************************************************************
* Load `$localize` onto the global scope - used if i18n tags appear in Angular templates.
*/
import '@angular/localize/init';

/**
* This file includes polyfills needed by Angular and is loaded before the app.
* You can add your own extra polyfills to this file.
*
...


我的 package.json依赖项
  "dependencies": {
"@angular/animations": "^9.1.1",
"@angular/common": "^9.1.1",
"@angular/compiler": "^9.1.1",
"@angular/core": "^9.1.1",
"@angular/forms": "^9.1.1",
"@angular/localize": "^9.1.1",
"@angular/platform-browser": "^9.1.1",
"@angular/platform-browser-dynamic": "^9.1.1",
"@angular/router": "^9.1.1",
"core-js": "^3.0.0",
"moment": "^2.24.0",
"prismjs": "^1.16.0",
"rxjs": "~6.5.5",
"tslib": "^1.10.0",
"zone.js": "~0.10.2"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.901.1",
"@angular-devkit/build-ng-packagr": "~0.901.1",
"@angular/cli": "^9.1.1",
"@angular/compiler-cli": "^9.1.1",
"@angular/language-service": "^9.1.1",
"@types/jasmine": "^3.3.13",
"@types/jasminewd2": "^2.0.6",
"@types/node": "^12.11.1",
"codelyzer": "^5.1.2",
"jasmine-core": "~3.4.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "^4.2.0",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage-istanbul-reporter": "^2.1.0",
"karma-jasmine": "^2.0.0",
"karma-jasmine-html-reporter": "^1.4.2",
"ng-packagr": "^9.0.0",
"ts-node": "^8.2.0",
"tslint": "^5.18.0",
"typescript": "~3.8.3"
}

最佳答案

我发现必须将@angular/localize/init导入test.ts才能运行测试,有关示例,请参见here

关于Angular 9 i18n迁移-测试失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61212554/

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