Skip to content
Advertisement

In Jest, how do I cause a function called within the function to return a specific value

This is the function I am testing (stripped down for simplicity’s sake): populate.js->

JavaScript

The function this function calls: populate-template-utilities ->

JavaScript

And my unit test (again stripped down):

JavaScript

I want createSessionID to return ‘PAX123456’ and think mockID should do it, but it’s erroring with:

JavaScript

Advertisement

Answer

The spyOn method needs at least two parameters: object and methodName.

Try sth like this:

JavaScript

It all started to work when I changed the:

JavaScript

to:

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