module-a.js
class Math {
pi() {
return 3.14;
}
}
export default Math
module-b.js
import Math from './module-a';
const piVal = Math.pi();
export const doSomeCalc = (a) => {
return piVal + a;
}
module-b.test.js
describe('module b', () => {
it('should return correct value', () => {
// I want to mock the return value of pi() here
return import('./module-b').then(module => {
expect(
module.doSomeCalc(20)
).toBe(23.14);
});
});
})
How do I mock Math.pi() here?
I need to import the module dynamically as Math.pi()
is evaluated as soon as I import the module.