main.js是这样的
const p0 = (a, b) => (a+b)
const p1 = (a, b) => {
return p0(a, b) + 10;
}
module.exports = { p1 }
测试代码
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 未定义
我认为 rewire 可以访问私有功能,请问如何解决这个问题?谢谢 !