I have two files, one in which I initialize a slack web API client, and post a message, and test this based on a mocked value:
main.ts:
import { WebClient } from '@slack/web-api';
const slack = new WebClient(process.env.SLACK_API_KEY as string);
slack.chat.postMessage({...});
test.ts
import { WebClient } from '@slack/web-api';
let slack: WebClient;
beforeAll(async () => {
slack = new WebClient();
});
jest.mock('@slack/web-api', () => {
return {
chat: jest.fn(),
postMessage: jest.fn(),
};
});
describe('test', () => {
it("tests slack message", async () => {
expect(slack.chat.postMessage).toBeCalledWith({...});
})
})
The problem is when I run this code I get the following error: TypeError: web_api_1.WebClient is not a constructor
I've tried various different ways including mocking the module, using esModule: true, not defining WebClient. My question is what am I doing wrong?