I want to mock AWS API call, and return a different value after each call
I now know that Sinon provides Oncall, which allows each call to return a different value
let stubCall = sandbox.stub(Math, "random");
stubCall.onCall(0).returns(Promise.resolve(0));
stubCall.onCall(1).returns(Promise.resolve(-1));
but I currently use a framework, aws-sdk-mock, which is mainly used to model API calls from AWS SDK. The method is as follows:
AWS.mock("CloudFormation", "describeStacks", Promise.resolve(stackResponse));
then I let it use OnCall and all of the following methods failed
1.
AWS.mock ("CloudFormation"," describeStacks", Promise.resolve (stackResponse)) .onCall (0) .returns (Promise.resolve (res));
2.
let mockCall = AWS.mock ("CloudFormation"," describeStacks", Promise.resolve (res));
mockCall.onCall (0). Returns (Promise.resolve (res));
both of them didn"t work.
but I think the discussion on GitHub says that https://github.com/dwyl/aws-s.
should be able to use the method. of OnCall because the framework itself is Hook Sinon,.
does anyone know how to use it? Or is there another way for me to mock AWS SDK API Call and return different values?
the test runner used by NodeJS is mocha
. Almost all the words I see on the website are Callback, but I use promise ().. AWS supported that all methods can be used last year, so the result returned by mocke must be promise ()