Using with DynamoDB
With the Global Setup/Teardown and Async Test Environment APIs, Jest can work smoothly with DynamoDB.
Use jest-dynamodb Preset
Jest DynamoDB provides all required configuration to run your tests using DynamoDB.
- First, install
@shelf/jest-dynamodb
- npm
- Yarn
- pnpm
npm install --save-dev @shelf/jest-dynamodb
yarn add --dev @shelf/jest-dynamodb
pnpm add --save-dev @shelf/jest-dynamodb
- Specify preset in your Jest configuration:
{
"preset": "@shelf/jest-dynamodb"
}
- Create
jest-dynamodb-config.js
and define DynamoDB tables
See Create Table API
module.exports = {
tables: [
{
TableName: `files`,
KeySchema: [{AttributeName: 'id', KeyType: 'HASH'}],
AttributeDefinitions: [{AttributeName: 'id', AttributeType: 'S'}],
ProvisionedThroughput: {ReadCapacityUnits: 1, WriteCapacityUnits: 1},
},
// etc
],
};