2

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 !

user3552178
  • 2,719
  • 8
  • 40
  • 67

1 Answers1

2

First argument should be string or object.

Try

myMod.__set__('p0', mockP0);  

or

myMod.__set__({p0: mockP0});  
vp_arth
  • 14,461
  • 4
  • 37
  • 66