D
D
danilr2020-11-01 18:49:00
JavaScript
danilr, 2020-11-01 18:49:00

How to rewrite mocks from jest.mock method to jest.spyOn?

Let's say there is such a mock, but it is not suitable for all tests, so they asked me to remake it on spyOn - after each test, reset it, having smoked the documentation and did not understand who fumbles in jest, tell me?

jest.mock('/../data/api', () => {
  const apiData: {makeApiData} = require('@bcs/sdk/lib/sdk-core/monads/api-data');

  return ({
    StatusName: {
      Confirmed: 'Подтвержден',
      InWork: 'В работе',
    },
    ProcessingWay: {
      Outbound: 'Outbound',
    },
    dentityCheck: {
      Courier: 'Курьер',
    },
    Api: jest.fn(() => ({
      getId: () => () => apiData.makeApiData(success(data)),

      getIds: () => () => apiData.makeApiData(success(data2))
    }),
  });
};

well, the test itself, but it is not important, someone will ask you to show it to anyone)
it('test', async () => {
    const dispatched = await recordSaga(dataSaga, { payload: '10101', type: dataConst });
    expect(dispatched).toBe(true);
  });

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question