dwyl/aws-sdk-mock

Trouble mocking step functions

lj91421 opened this issue · 3 comments

I have a function calling stepfunctions.startExecution(params) which i need to mock and the mock i am trying isn't working.

My function:

export const function= async (inputs): Promise<StepFunctions.StartExecutionOutput> => {
  const stepfunctions = new StepFunctions();
.
.
.
  const params = {
    stateMachineArn,
    input: inputs,
    name: executionName,
  };

  return stepfunctions.startExecution(params).promise();
};

and my test looks like:

 it('should trigger step functions to start', async () => {
    const response = 'Step function started';
    AWSMock.setSDKInstance(AWS);
    AWSMock.mock(stepFunctions, 'startExecution', response);
    const result = await issueReport(qualificationId, sessionId, date);
    expect(result).toEqual(response);
    AWSMock.restore(stepFunctions);
  });

Am i doing something wrong?

Packages:
"aws-sdk": "^2.847.0",
"aws-sdk-mock": "^5.1.0",
"jest": "26.6.0",

Hey @lj91421 , I too am facing this issue. Did you end up resolving it?

@lprhodes This does seem to be working for me now. I only changed the mocking of the start execution. it looks like:

AWSMock.mock(stepFunctions, 'startExecution', (params: any, callback: any) => { callback(null, response); });

Thanks @lj9142 For us it was the difference between import * as AWSMock and import AWSMock that caused the problem