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
I stumbled on this when the code I was testing had provided undefined as a parameter for SQS.sendMessage().
When all params that the AWS SDK expects are present, then the mock works, and all of my mocked behavior gets executed during the test. When any required params are missing from the parameter object, the mocked behavior is never invoked, and the call throws a "MissingRequiredParameter" error.
Sample test code:
import { handler } from "./my-handler";
import AWS from "aws-sdk";
import AWSMock from "aws-sdk-mock";
describe("My handler", function () {
it("should do something", async () => {
AWSMock.setSDKInstance(AWS);
AWSMock.mock("SQS", "sendMessage", (params, callback) => { callback(null, {foo: "bar"}); });
const result = await handler(event);
expect(result).toMatchObject({
statusCode: 201,
});
AWSMock.restore("SQS");
});
});
If in your code you are using aws sdk's getQueueUrl() method, you might need to mock that as well.
In the above unit code, I assume the QueueURL is populated correctly
I stumbled on this when the code I was testing had provided undefined as a parameter for SQS.sendMessage().
When all params that the AWS SDK expects are present, then the mock works, and all of my mocked behavior gets executed during the test. When any required params are missing from the parameter object, the mocked behavior is never invoked, and the call throws a "MissingRequiredParameter" error.
Sample test code:
Sample unit code:
Snippet of package.json with dependencies:
The text was updated successfully, but these errors were encountered: