简体   繁体   中英

AWS Cognito Mock

I want to write BDD tests for my nodejs based API which uses AWS cognito as user authentication service, but I don't want to hit the real cognito service every time my build runs.

Is there an easy and elegant way to mock Cognito calls.

Used frameworks :

  • Nodejs (Hapi.js)
  • aws-sdk for nodejs

We have created an aws-sdk-mock npm module which mocks out all the AWS SDK services and methods. https://github.com/dwyl/aws-sdk-mock

It's really easy to use. Just call AWS.mock with the service, method and a stub function.

AWS.mock('CognitoIdentityServiceProvider', 'theCallYouWantToMock', function(params, callback) {
    callback(null, 'success');
});

Then restore the methods after your tests by calling:

AWS.restore('CognitoIdentityServiceProvider', 'theCallYouWantToMock');

How did you end up mocking the Cognito Service? I don't see any documentation.

Is it something like

AWS.mock('COGNITO', params, callback);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM