Skip to content

AWS SDK v3: Lazy Object.defineProperty re-exports break Jest auto-mocking #7748

@MxAshUp

Description

@MxAshUp

Checkboxes for prior research

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-dynamodb 3.988.0 ... 3.992.0 (last working version was 3.987.0)
  • jest 29.7.0 (also reproduced on 30.1.3)
  • ts-jest 29.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),
    })),
  };
});

Metadata

Metadata

Assignees

Labels

bugThis issue is a bug.p2This is a standard priority issuepending-releaseThis issue will be fixed by an approved PR that hasn't been released yet.potential-regressionMarking this issue as a potential regression to be checked by team member

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions