I'm working with Jest to mock my AWS services, and more specifically DynamoDB and DynamoDBDocumentClient.
My code is currently similar to this :
import { DynamoDBClient } from "@aws-sdk/client-dynamodb"
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb"
const ddbClient = new DynamoDBClient({})
const ddbDocumentClient = DynamoDBDocumentClient.from(ddbClient, config)
and the test spec looks like this:
jest.mock("@aws-sdk/client-dynamodb", () => ({
DynamoDBClient: jest.fn(() => ({
put: (params) => mockAwsResponse("DynamoDBClient", "GetCommand", params),
put: (params) => mockAwsResponse("DynamoDBClient", "PutCommand", params),
})),
}))
jest.mock("@aws-sdk/lib-dynamodb", () => ({
DynamoDBDocumentClient: jest.fn(() => ({
get: (params) => console.log("In DynamoDBClient get", params),
put: (params) => mockAwsResponse("DynamoDBDocumentClient", "PutCommand", params),
from: (params) => mockAwsResponse("DynamoDBDocumentClient", "from", params),
})),
}))
Unfortunately Jest returns me this error : TypeError: lib_dynamodb_1.DynamoDBDocumentClient.from is not a function
and I believe it's because I'm incorrectly mocking DynamoDBDocumentClient
, as its constructor is a static method.
Thanks in advance for your help!
EDIT: Just noticed that it used the AWS SDK v3 for JavaScript, if that helps.