I am attempting to simulate a call to the SQS method sendMessage()
that is used in the System Under Test (SUT) like this:
private async pushJobIntoQueue(network: Network) {
await this.contactInteractionsQueue.sendMessage(
JSON.stringify({
type: 'calculInteractions',
networkId: network.id,
isInteractionsShared: true,
}),
);
}
Below is the test scenario that I believed would be straightforward:
describe('NetworkService', () => {
let service: NetworkService;
let networkRepo: Repository<Network>;
let memberRepo: Repository<Member>;
let sqsService: SqsService;
beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [
/* ... */
SqsService,
],
}).compile();
/* ... */
sqsService = module.get<SqsService>(SqsService);
});
it('should enqueue every network', async () => {
const networks = Array(20).fill(networkDataBuilder());
const expectedAddedNetwork = networks.length;
const queue = sqsService.initQueue('cm-contact-interactions');
queue.sendMessage = jest.fn();
expect(queue.sendMessage.mock.calls.length).toBe(expectedAddedNetwork);
});
The TypeScript error occurs on the second to last line at queue.sendMessage
:
TS2339: Property 'mock' does not exist on type '(type: string) => Promise'.