Skip to content

Import Module Mocks special to each test or dynamic #5718

Closed Answered by enszrlu
enszrlu asked this question in Q&A
Discussion options

You must be logged in to vote

Sorted out the issue, for anyone needs it in the future please see below.

const mockExternalService = {
  getItem: vi.fn(),
 ..... 
};

vi.mock('../external/ExternalService', () => {
  class MockExternalService implements ExternalService {
    async getItem(symbol: string) {
      return mockExternalService.getItem(symbol);
    }

  ........ 
  }

  return {
    default: MockExternalService,
  };
});

mockExternalService.getItem.mockResolvedValue(....... )

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by enszrlu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant