how do you duplicate a mocked module?

I’ve been having success overwriting the module’s methods with mocks manually and ts plays super nice with them:

import * as userService from './services/usesService';

const fetchUsersMock = jest.mock();
const fetchBriefMock = jest.mock();

userService.fetchUsers = fetchUsersMock;
userService.fetchBrief = fetchBriefMock;

describe('something', () => {
  beforeEach(() => {
    fetchBriefMock.mockClear();
    fetchUsers.mockClear();
  });
});

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top