Cannot find module 'angular-oauth2-oidc' during Jest testing

Viewed 40

I've imported import { OAuthService } from 'angular-oauth2-oidc'; and I have it installed via npm (https://www.npmjs.com/package/angular-oauth2-oidc) and I'm using the latest version 13.0.1 but my jest test is failing stating that it cannot find the module

> 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)

I'm currently using Angular 12, Jest 26.6.3, Typescript 4.2.4

Am I missing something because I'm not getting any errors in the actual file :/

1 Answers

In my package.json I had version "angular-oauth2-oidc": "13.0.1". Even though the package said it should work with "older versions", once I changed it to "12.0.1" to match my Angular version, it removed the "cannot find module" error.

Related