How To Mock Nested Function In Jest?
I am getting this error Cannot find module 'httpsGet' from 'functions/getSecureString.test.js' httpsGet() is my own function, and is at the button of getSecureString.js, and calle
Solution 1:
A function that is used in the same module it was declared cannot be spied mocked, unless it's consistently as a method of some object, which is cumbersome and incompatible with ES modules:
module.exports.httpsGet = ...
...
module.exports.httpsGet(...);
Otherwise a function should be moved to another module that can mocked, or should be tested as is. In this case underlying API (https.get
) can be mocked instead.
Post a Comment for "How To Mock Nested Function In Jest?"