@sls-testing/jest
v1.0.1
Published
Jest custom matchers for AWS Lambda testing — extends expect with serverless-specific assertions
Downloads
255
Maintainers
Readme
@sls-testing/jest
Custom Jest matchers for testing AWS Lambda functions.
Install
npm install @sls-testing/core @sls-testing/jest --save-devSetup
Add to your Jest config:
{
"setupFilesAfterEnv": ["@sls-testing/jest"]
}Or import in your test file:
import '@sls-testing/jest'Matchers
Status Code
expect(response).toHaveStatusCode(200)
expect(response).toBeSuccessfulApiResponse() // 2xx
expect(response).toBeClientError() // 4xx
expect(response).toBeServerError() // 5xxLambda Response
expect(response).toMatchLambdaResponse({
statusCode: 201,
body: { userId: expect.any(String) }, // asymmetric matchers work
headers: { 'content-type': 'application/json' },
})SQS Batch
expect(sqsResponse).toHaveNoFailedMessages()
expect(sqsResponse).toHaveFailedMessage('msg-id-2')Side Effects
const spy = jest.spyOn(service, 'sendEmail')
await handler(event, context)
expect(spy).toHaveNoSideEffects()Setup Helper
import { setupServerlessTesting } from '@sls-testing/jest'
const cleanup = setupServerlessTesting({
timezone: 'UTC',
suppressLogs: true,
})
afterAll(() => cleanup())License
MIT
