【问题标题】:Cannot find module 'angular-oauth2-oidc' during Jest testing在 Jest 测试期间找不到模块“angular-oauth2-oidc”
【发布时间】:2022-08-23 02:36:05
【问题描述】:

我已经导入了 import { OAuthService } from \'angular-oauth2-oidc\'; 并通过 npm (https://www.npmjs.com/package/angular-oauth2-oidc) 安装了它,并且我使用的是最新版本 13.0.1 但是我的笑话测试失败了,说明它找不到模块

> 6 | import { OAuthService } from \'angular-oauth2-oidc\';
    | ^
  7 | import { Injectable } from \'@angular/core\';
  8 | import { EnvironmentService } from \'../environment/environment.service\';
  9 | import { IGncUser } from \'../../shared/interfaces/iGncUser\';

  at Resolver.resolveModule (node_modules/jest-resolve/build/index.js:306:11)
  at Object.<anonymous> (src/app/core/authentication/authentication.service.ts:6:1)

我目前正在使用 Angular 12、Jest 26.6.3、Typescript 4.2.4

我是否遗漏了什么,因为我在实际文件中没有收到任何错误:/

    标签: angular unit-testing jestjs ts-jest


    【解决方案1】:

    在我的 package.json 中,我有版本“angular-oauth2-oidc”:“13.0.1”。即使包说它应该与“旧版本”一起使用,一旦我将它更改为“12.0.1”以匹配我的 Angular 版本,它删除了“找不到模块”错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-30
      • 2022-12-22
      • 2020-04-30
      • 1970-01-01
      • 2020-02-15
      • 2019-10-30
      • 2022-06-12
      相关资源
      最近更新 更多