I have two issues
- I want to mock the config.get() from config lib to return a value
- The mocked return value for config.get should be a date generated from moment
I tried the following but I get an error "is not allowed to reference any out-of-scope variables. Invalid variable access: moment"
Say my function:
function test(configVariable) {
const variable = config.get(configVariable)
}
Test function
jest.mock('config', () => ({
default: {
get: () => jest.fn().mockImplementation(() => {
const dDate = moment();
dDate.subtract(1, 'd');
dDate.format('YYYY-MM-DD');
return dDate;
}),
}
}));
Could some one please help me with the same and thanks in advance for your time.