Skip to content
Advertisement

TypeError: jwt(…).unless is not a function when mocking with Jest

I am trying to mock the .unless function of express-jwt and currently have this mock setup to compare a JWT with an admin and non admin. This worked perfect until we added .unless and I am not sure the best way to approach the issue.

JavaScript

That is the mock. I have tried moving that into a const and adding: mockFun.unless = jest.fn() but to no avail.

Thanks

Edit:

One of the things I tried is below:

JavaScript

Advertisement

Answer

unless is supposed to be a method on a function that jwt() returns while currently it’s a method on jwt itself.

Should be:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement