Jest how to mock api call Jest how to mock api call reactjs reactjs

Jest how to mock api call


The import are immutable so it won't work, what you should is mock the whole module. Either with a __mock__ directory or simply with:

jest.mock('../../util/api');const { call } = require('../../util/api');call.mockImplementation( () => console.log("some api call"));