I want to mock a static method defined outside a component.
Here is my component:
import Authenticate from '/api/Authenticate';
export default class MyComponent extends React.Component {
render() {
if (Authenticate.hasGroup()) {
return (<div>Has group</div>);
} else {
return (<div>No group</div>);
}
}
}
hasGroup is a static method defined in Authenticate and returns boolean.
Here is my test file
describe('Has Group', () => {
jest.doMock('/api/Authenticate', () => ({
__esModule:true,
hasGroup: jest.fn(()=>true)
});
);
it('render has group', ()=>{
const wrapper = render(<MyComponent/>);
expect(toJson(wrapper)).toMatchSnapshot();
})
}
When I run the test, hasGroup method is not mocked. What am I missing?