运行 使用 Jest 测试时找不到模块“@ngrx/effects”

Cannot find module '@ngrx/effects' when running tests with Jest

在我们的 angular 应用程序中尝试 运行 开玩笑测试时,我收到以下消息:

Cannot find module '@ngrx/effects' from 'src/app/modules/core/core.module.ts'

这很奇怪,因为应用程序 运行s 和解析这个模块没有问题,当我尝试在我们的 setup-[=65= 中导入这个模块时也会出现这个错误]。 jest 的解析器似乎找不到这个。

来自应用程序配置的片段

package.json:

"dependencies": {
"@angular/animations": "~12.1.2",
"@angular/cdk": "^12.1.2",
"@angular/common": "~12.1.2",
"@angular/compiler": "^12.1.2",
"@angular/core": "~12.1.2",
"@angular/forms": "~12.1.2",
"@angular/material": "^12.1.2",
"@angular/platform-browser": "~12.1.2",
"@angular/platform-browser-dynamic": "~12.1.2",
"@angular/router": "~12.1.2",
"@angular-devkit/build-angular": "^12.1.2",
"@angular-eslint/builder": "12.3.1",
"@angular-eslint/eslint-plugin": "12.3.1",
"@angular-eslint/eslint-plugin-template": "12.3.1",
"@angular-eslint/schematics": "12.3.1",
"@angular-eslint/template-parser": "12.3.1",
"@angular/cli": "~12.1.2",
"@angular/compiler-cli": "^12.1.2",
"@ngrx/schematics": "^13.0.2",
"@ngrx/effects": "^13.1.0",
"@ngrx/store": "^12.5.1",
"@ngrx/store-devtools": "^12.5.1",
"@ngx-translate/core": "^13.0.0",
"@ngx-translate/http-loader": "^6.0.0",
...

jest 配置(也在 package.json 中)

"jest": {
"preset": "jest-preset-angular",
"setupFilesAfterEnv": [
  "<rootDir>/setup-jest.ts"
],
"testPathIgnorePatterns": [
  "<rootDir>/node_modules/",
  "<rootDir>/dist/"
],
"moduleDirectories": [
  "node_modules"
],
"moduleNameMapper": {
  "^@environments/(.*)": "<rootDir>/src/environments/",
  "^@app/(.*)": "<rootDir>/src/app/"
},
"testMatch": [
  "**/__tests__/**/!(DISABLED.)*.[jt]s?(x)",
  "**/!(DISABLED.)?(*.)+(spec|test).[tj]s?(x)"
],
"globals": {
  "ts-jest": {
    "tsConfig": "<rootDir>/tsconfig.spec.json",
    "stringifyContentPathRegex": "\.html$"
  }
} 
...

需求栈如下:

在我们的应用程序模块中导入:

StoreModule.forRoot(reducers),
EffectsModule.forRoot([]),
...

在我们的核心模块导入中:

StoreModule.forFeature(fromCore.coreFeatureKey, fromCore.coreReducer),
EffectsModule.forFeature([CoreEffects])
...

最后,导入核心模块的设备模块:

 imports: [
    CoreModule,
    ...

错误: console output of the error

我试过的:

我是 angular 的新手,它正在测试,我试图查找以前的答案并重新检查我的 angular 和 ngrx 课程,但不知道问题出在哪里。非常感谢任何想法或意见!提前致谢!

请尝试保持所有 angular 和 ngrx 版本相同。 在这种情况下,将ngrx效果下载到v12.