Jest mock module multiple times with different values
问题 I have a function that I want to test and this function uses an imported module: var a = require('./a'); function add(b) { return a + b; } module.exports = add; That a module returns a number in this sample, but in my real project I use that as a config object that is changed from time to time manually. var a = 1; module.exports = a; The test for the add function looks like this: describe('add', () => { it('should add the mock number 1 to 2', () => { jest.setMock('./a', 1); const add =