![]() Problem is that the test always passes, meaning it never hiu. But the problem with 'lambda-tester' is, it will hit the actual service and return the data. Easily mock the AWS SDK using jest NovemWhat is mocking and why should we use it When testing code that makes use of the AWS SDK you are guaranteed to run into issues right away. Mock functions allow you to test the links between code by erasing the actual implementation of a function, capturing calls to the function (and the parameters passed in those calls), capturing instances of constructor functions when instantiated with new, and allowing test-time configuration of return values. I used a node module called 'lambda-tester' to test it. ![]() ![]() // No need to import aws-sdk in the test file, we will mock it! // ⚠️ Mock instance needs to be initialized before the module-in-test is required, // otherwise will get this error: // "ReferenceError: Cannot access 'mockIotDataInstance' before initialization" // // ⚠️ Variable name is ALSO IMPORTANT! It has to start with 'mock', // otherwise we will get this error: // "ReferenceError (.) // The module factory of `jest.mock()` is not allowed to reference any out-of-scope variables. In code below I'm trying to test method getParameter for failure. I was trying to write a jest unit test cases for AWS lambda function(for node environment).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |