Advertisement

TrimwebsolutionsTrimwebsolutions

Problem and Solutions

Mock a function used inside a react.js component "multiple times" ?

By M.K. Verma · 2 May 2022

Mock a function used inside a react.js component "multiple times" ?

Try this,

jest.mock("@myORG/axiosWrapperReactQuery", () => {
const original = jest.requireActual("@myORG/axiosWrapperReactQuery");
return {
  ...original,
  getAllCourses: jest.fn()
                 .mockImplementationOnce(() => ({
                             isLoading: false, // 1st call
                             typedData: [],
                 }))
                 .mockImplementationOnce(() => ({
                             isLoading: true, // 2nd call
                             typedData: [],
                 }))
}