I have ES-6 class which is having static methods. How to mock them in Jest to test if they gets called?
I have 3 files
- Logger
class Logger {
static log = (err) => {
console.log(err);
}
}
export default Logger;
- action
// import Logger './Logger';
export const myAction = () => {
handleRequest(params).then((response) => {
// Statements
}).catch((err) => {
Logger.log(err);
});
};
- Test file
// import {myAction} from './action';
// import Logger './Logger';
it('should call Logger', () => {
Logger.log = jest.fn();
return myAction().then(() => {
expect(Logger.log).toHaveBeenCalled(); // It is failing
});
});