You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here is a reduced example of what I'm trying to do.
I have a class with a function that looks like this:
// at the top of the fileconstApiGatewayManagementApi=require('aws-sdk/clients/apigatewaymanagementapi');// function definitionasyncsendSummary(summary,{ endpoint, connectionId }){constapiGwManagementApi=newApiGatewayManagementApi({ endpoint });returnapiGwManagementApi.postToConnection({ConnectionId: connectionId,Data: JSON.stringify(summary),}).promise().catch((err)=>{console.error('Error while sending',err);throwerr;});}
That works as expected. Now comes the part of the test
constAWS=require('aws-sdk-mock');it('send summary',async()=>{AWS.mock('ApiGatewayManagementApi','postToConnection',function(params,callback){expect(params).toEqual(jasmine.objectContaining({ConnectionId: connectionId,Data: JSON.stringify(summary),}));callback(null,{});});const{ service }=require('../my-service');awaitexpectAsync(service.sendSummary(summaryMock,connectionMock)).toBeResolved();AWS.restore('ApiGatewayManagementApi');});
The solution is to replace this const ApiGatewayManagementApi = require('aws-sdk/clients/apigatewaymanagementapi');
and this const apiGwManagementApi = new ApiGatewayManagementApi({ endpoint });
with this const AWS = require('aws-sdk');
and this const apiGwManagementApi = new AWS.ApiGatewayManagementApi(({ endpoint });
Here is a reduced example of what I'm trying to do.
I have a class with a function that looks like this:
That works as expected. Now comes the part of the test
But when running the tests it throws the error
Seems like the mock is not working. Any help is appreciated.
The text was updated successfully, but these errors were encountered: