我想测试一个js文件,该文件中包含来自另一个导入的const引用(parser.js)
const { cp } = CML
我如何模拟这个,而仅模拟这个,而不模拟其余的功能?。它抛出此错误:
ReferenceError: CML is not defined
at Object.<anonymous> (src/state/lib/parser.js:2:16)
at Object.<anonymous> (src/state/reducers/stateReducer.js:2:1)
at Object.<anonymous> (src/state/reducers/index.js:4:1)
at Object.<anonymous> (src/state/store/index.js:4:1)
at Object.<anonymous> (src/state/store/store.spec.js:4:1)
CML是在其他js资源文件中定义的var。
jest.mock('./state/lib/parser', function() { // Put the exact path you've imported in your file
return {
CML: 123,
};
});