-1

I have a React application that is providing a third party SSO via Okta, so making use of the @okta/okta-auth-js package.

Have an authentication file that defines an instance of OktaAuth and passes the setup config:

import OktaAuth, { OktaAuthOptions } from '@okta/okta-auth-js';

const oktaConfig: OktaAuthOptions = {
  issuer: `issuer_val_here`,
  ...etc,
};

const oktaAuth = new OktaAuth(oktaConfig);

All running fine in app, but when it comes to running jest tests of components that make use of this authentication file in any way I'm getting the immediate error:

TypeError: _oktaAuthJs.default is not a constructor

      28 | };
      29 |
    > 30 | const oktaAuth = new OktaAuth(oktaConfig);
         |                  ^

I've tried to mock this and set it up so many different ways from git threads and forum posts, I've tried:

   "moduleNameMapper": {
      "^@okta/okta-auth-js$": "<rootDir>/node_modules/@okta/okta-auth-js/dist/okta-auth-js.min.js"
    }

in the package.json

I've tried all of the different combinations of jest.mock and mocking in setupTests.js that I can think of and I'm still getting this error with no change

Has anyone dealt with this before and got it work?

foakesm
  • 803
  • 10
  • 18

1 Answers1

0

Your import should be:

import { OktaAuth, OktaAuthOptions } from '@okta/okta-auth-js';

instead of

import OktaAuth, { OktaAuthOptions } from '@okta/okta-auth-js';
jndietz
  • 1,216
  • 1
  • 11
  • 12