Skip to content

A collection of matchers and spies for testing AWS serverless applications

Notifications You must be signed in to change notification settings

serverless-guru/sls-jest

Repository files navigation

sls-jest

Continuous Integration Release

sls-jest logo

A jest extension to test serverless applications.


Testing serverless applications is hard. Ideally, you want to test against the real infrastrucutre and avoid mocks. e.g. a real DynamoDB table, real Lambda functions. However, the asynchronous nature of serverless makes it difficult to write tests that work and are deterministic.

This library offers a suite of tools that help solve, or at least mitigate, those issues. It is built on top of the famous jest library and adds new serverless-related matchers.

Getting started

Install sls-jest

npm i sls-jest

Setup Jest

Create a setup file:

// setupJest.ts
import { matchers } from 'sls-jest';

expect.extend(matchers);

Then use it in your jest config file (jest.config.ts) under setupFilesAfterEnv:

export default {
  // ..
  setupFilesAfterEnv: ['./setupJest.ts'];
}

Documentation

For full documentation and guides, read the documentation website.