0

This is the code that i have to mock in testing

 import * as jwtDecode from 'jwt-decode';
 const reg: string = jwtDecode<ITokenDTO>(token)['jti'];

and i am going to use this reg as const result = await thirdpartylib.some_method(getToken(reg));

and this is what i have written so far jest.mock('jwt-decode', () => () => ({})) but i am not sure whether its right or wrong, can someone correct it if it is wrong or give the confirmation if it is right.

Anyno328
  • 15
  • 3

1 Answers1

0

It may be marked as a duplicated. The answer here below has a good explanation, and the proposed solution could be a right one:

https://stackoverflow.com/a/60398466

The solution that worked for be is the following:

import jwtDecode from 'jwt-decode';

jest.mock('jwt-decode', () => ({ default: jest.fn(() => ({})) }));

...

      expect(jwtDecode).toBeCalledWith('whatever');
hastudil
  • 26
  • 2