I would like to know how can I mock an imported object for return a fake value with Jest.
In this case, I want to override the default timeout value (5000) to 1000 to crash my function
// config.ts
export const config = {
request: {
timeout: 5000,
},
};
// Test file
import * as config from './config';
describe('Requests', () => {
beforeEach(() => {
jest.mock('./config');
});
afterEach(() => {
jest.resetAllMocks();
});
it('Force timeout value', () => {
jest.mock('./config');
config.request.timeout.mockReturnValueOnce(1000);
expect(config.request.timeout).toEqual(1000); // FAIL: returns 5000 instead of 1000
});
});
Thank you!