Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

aws-lambda-mock-context

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

aws-lambda-mock-context

This library returns a mock context object that can be used to test lambda functions.

  • 0.1.0
  • npm
  • Socket score

Version published
Weekly downloads
16K
increased by14.46%
Maintainers
1
Weekly downloads
 
Created
Source

aws-lambda-mock-context

This library returns a mock context object that can be used to test lambda functions

Installation

npm install --save aws-lambda-mock-context

Usage

The library can be used in combination with SinonJS to test if the correct methods are called.

// module dependencies
var chai = require('chai'),
    sinon = require('sinon'),
    sinonChai = require('sinonChai'),
    Q = require('q'),
    ctx = require('aws-lambda-mock-context');;

// Use the should flavour
chai.should();
chai.use(sinonChai);

// Start the test
describe('Lambda Test', function() {
    
    // Create a new context
    var ctx = context();
    
    beforeEach(function() {
        // Spy the succeed function
        sinon.spy(ctx, 'succeed');
    });
    
    afterEach(function() {
        // Restore it back to normal
        ctx.succeed.restore();
    });
    
    it('Should call the succeed method', function(done) {
        Q.fcall(function() {
            // Call the handler method
            return index.handler({hello: 'world'}, this.ctx);
        }).then(function() {
            // Test if the succeed method is called once
            ctx.succeed.should.be.calledOnce;
            
            done();
        });
    });
});

If the handler method is asynchronous, make sure it returns a promise. If you don't return a promise, the test will fail. This is because the handler returns but at that moment, the succeed method is not yet called.

Contributors

License

MIT © Sam Verschueren

Keywords

FAQs

Package last updated on 27 Jul 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc