fix(subdirectory): use explicit __esModule mock shape for getBootstrapData

requireActual spread didn't fix the Layer 5 crash — consumers still hit
"_getBootstrapData.default is not a function". Most plausibly the SWC
transform produces a default-export shape that requireActual doesn't
faithfully round-trip when spread into a fresh object literal.

Mirror the established pattern from CrudThemeProvider.test.tsx and
Register.test.tsx: explicit { __esModule: true, default, applicationRoot,
staticAssetsPrefix }. Default returns a BootstrapData-shaped object that
reads from mockApplicationRoot so any consumer that pulls
common.application_root through the default path also sees the mocked
value. staticAssetsPrefix mocked as a no-op since none of the touched
code paths exercise it.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Joe Li
2026-05-07 11:35:49 -07:00
parent 11a47c63a3
commit 7d6d33fa09

View File

@@ -49,15 +49,23 @@ import SliceHeaderControls, { SliceHeaderControlsProps } from '.';
// "module factory is not allowed to reference any out-of-scope variables".
const mockApplicationRoot = jest.fn<string, []>(() => '');
// `getBootstrapData` exposes both a default export (the bootstrap getter
// itself) and named exports like `applicationRoot`. Consumers in the
// component tree transitively import the default — replacing the module
// with just `{ applicationRoot }` left default undefined and crashed at
// require-time. Spread `requireActual` to preserve everything else and
// override only `applicationRoot`.
// Mirror the actual module shape: __esModule + default getBootstrapData
// + named applicationRoot/staticAssetsPrefix. Consumers in the
// SliceHeaderControls import chain transitively call the default export,
// so a mock that omits it crashes at require-time. (Spreading
// jest.requireActual was tried first — it executes the real module body,
// which reads applicationRoot from cached module state and produces the
// wrong default-export shape under SWC/Babel ESM interop.)
jest.mock('src/utils/getBootstrapData', () => ({
...jest.requireActual<object>('src/utils/getBootstrapData'),
__esModule: true,
default: () => ({
common: {
application_root: mockApplicationRoot(),
static_assets_prefix: '',
},
}),
applicationRoot: () => mockApplicationRoot(),
staticAssetsPrefix: () => '',
}));
const SLICE_ID = 371;