dwyl / aws-sdk-mock

:rainbow: AWSomocks for Javascript/Node.js aws-sdk tested, documented & maintained. Contributions welcome!
Apache License 2.0
1.11k stars 110 forks source link

Trouble mocking step functions #232

Open lj91421 opened 3 years ago

lj91421 commented 3 years ago

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",

lprhodes commented 3 years ago

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

lj9142 commented 3 years ago

@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); });

lprhodes commented 3 years ago

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