Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trouble mocking step functions #232

Open
lj91421 opened this issue Mar 12, 2021 · 3 comments
Open

Trouble mocking step functions #232

lj91421 opened this issue Mar 12, 2021 · 3 comments

Comments

@lj91421
Copy link

lj91421 commented Mar 12, 2021

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
Copy link

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

@lj9142
Copy link

lj9142 commented May 11, 2021

@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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants