How to mock a function with Jest in Firebase Cloud Functions while testing with Firebase Emulator Suite?

Viewed 130

The function is being called from a Cloud Function being triggered on Firestore db change.

This is what I tried so far:

const slackMock = jest.spyOn(chatUtils, 'slackPostMessage');
slackMock.mockImplementation(async (message: string, conversationId: string) => {
    console.log('Slacks Mock called with message: ' + message + '\nConversation id:' + conversationId);
    return test;
});



// In the test:
console.log(slackMock.mock.results);  // returning => []

The function being mocked sends a message on Slack which actually gets triggered despite mocking the function. What's the correct way to mock when using Firebase Emulator Suite?

0 Answers
Related