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.
npm i sls-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'];
}
For full documentation and guides, read the documentation website.