AWS Cognito Mock

一曲冷凌霜 提交于 2020-12-08 06:10:37

问题


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

回答1:


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');


来源:https://stackoverflow.com/questions/35008015/aws-cognito-mock

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!