Angular 13 + 笑话 + Angular 库不工作

dhc*_*ode 4 jestjs angular jest-preset-angular

我正在尝试在 Angular 13 项目中使用 jest 进行测试。我将 jest-preset-angular 与 @angular-builders/jest 一起使用。

我使用 ngx-pipes,这是一个不是为 Angular 13 编译的库。它在正常的 Angular 构建过程中工作正常。但在玩笑测试运行中它会导致错误:

Error: Unexpected value 'NgStringPipesModule2' imported by the module 'DynamicTestModule'. Please add an @NgModule annotation.
Run Code Online (Sandbox Code Playgroud)

最小复制:https ://github.com/dhcode/jest-preset-angular-13-issue

在我的实际项目中,我对其他 Angular 库也有同样的错误。我之前跑过ng serve,所以ngcc编译是在运行测试之前完成的。

如何让我的测试运行并识别使用较旧的 Angular 版本构建的外部库?

ste*_*nja 6

从表面上看,ngx-pipes还没有发布 Ivy 发行版,您的项目ngcc在运行测试之前仍然需要。

\n
// package.json\n{\n  "scripts": {\n    "test": "ngcc && ng test"\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n
> jest-tests@0.0.0 test\n> ngcc && ng test\n\nProcessing legacy "View Engine" libraries:\n- ngx-pipes [fesm2015/esm2015] (https://github.com/danrevah/ngx-pipes.git)\n- ngx-pipes [esm2015/esm2015] (https://github.com/danrevah/ngx-pipes.git)\n- ngx-pipes [main/umd] (https://github.com/danrevah/ngx-pipes.git)\nEncourage the library authors to publish an Ivy distribution.\n PASS  src/app/app.component.spec.ts\n  AppComponent\n    \xe2\x9c\x93 should create the app (163 ms)\n    \xe2\x9c\x93 should have as title \'jest-tests\' (46 ms)\n    \xe2\x9c\x93 should render title (44 ms)\n    \xe2\x9c\x93 should render shortened text (33 ms)\n\n-------------------|---------|----------|---------|---------|-------------------\nFile               | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s \n-------------------|---------|----------|---------|---------|-------------------\nAll files          |     100 |      100 |     100 |     100 |                   \n ...component.html |     100 |      100 |     100 |     100 |                   \n app.component.ts  |     100 |      100 |     100 |     100 |                   \n-------------------|---------|----------|---------|---------|-------------------\nTest Suites: 1 passed, 1 total\nTests:       4 passed, 4 total\nSnapshots:   0 total\nTime:        3.526 s, estimated 5 s\nRan all test suites.\n
Run Code Online (Sandbox Code Playgroud)\n