-
Notifications
You must be signed in to change notification settings - Fork 666
Description
Checkboxes for prior research
- I've gone through Developer Guide and API reference
- I've checked AWS Forums and StackOverflow.
- I've searched for previous similar issues and didn't find any solution.
Describe the bug
Summary
This bug is related to using Jest in combination with aws-sdk, so apologies if this is the wrong place for this, but a recently release change in @aws-sdk/client-dynamodb broke some tests.
Starting in @aws-sdk/client-dynamodb 3.988.0, exception classes like ConditionalCheckFailedException are re-exported from the package entrypoint via lazy Object.defineProperty getters. When Jest's jest.mock() auto-mock encounters these getters, it fails to resolve them — the exports become undefined at runtime.
This affects any test that auto-mocks an SDK client module and then references an exception class or other re-exported symbol from that same module.
Question
Maybe this isn't a bug, but intentional?
Is the switch to lazy Object.defineProperty getters for re-exported symbols (exception classes, command classes, etc.) intentional and permanent? Or is this an unintended side effect of a build tooling change?
Regression Issue
- Select this option if this issue appears to be a regression.
SDK version number
@aws-sdk/package-name@3.988.0
Which JavaScript Runtime is this issue in?
Node.js
Details of the browser/Node.js/ReactNative version
v22.17.0
Reproduction Steps
import { ConditionalCheckFailedException } from "@aws-sdk/client-dynamodb";
jest.mock("@aws-sdk/client-dynamodb");
test("exception class is defined", () => {
// Fails: ConditionalCheckFailedException is undefined
expect(ConditionalCheckFailedException).toBeDefined();
});Environment:
@aws-sdk/client-dynamodb3.988.0 ... 3.992.0 (last working version was 3.987.0)jest29.7.0 (also reproduced on 30.1.3)ts-jest29.2.5- Node 22
Observed Behavior
ConditionalCheckFailedException is undefined
Expected Behavior
ConditionalCheckFailedException should be defined
Possible Solution
No response
Additional Information/Context
Workaround
Use a manual mock factory with jest.requireActual() to preserve real exports:
const mockSend = jest.fn();
jest.mock("@aws-sdk/client-dynamodb", () => {
const actual = jest.requireActual("@aws-sdk/client-dynamodb");
return {
...actual,
DynamoDBClient: jest.fn().mockImplementation(() => ({
send: (...args: any[]) => mockSend(...args),
})),
};
});