The main.js is like this
const p0 = (a, b) => (a+b)
const p1 = (a, b) => {
return p0(a, b) + 10;
}
module.exports = { p1 }
The test code
const rewire = require('rewire');
const myMod = rewire('main');
it('.test p0', async() => {
const mockP0 = (a, b) => (a*b);
myMod.__set__(p0, mockP0);
return p1(2, 10);
});
ReferenceError: p0 is not defined
I thought rewire can access private functions, how to solve this pls ? Thx !
First argument should be string or object.
Try
myMod.__set__('p0', mockP0);
or
myMod.__set__({p0: mockP0});