Skip to content

Commit

Permalink
better namedExports mocks inside esbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
ChALkeR committed Oct 24, 2024
1 parent e154875 commit a7654cc
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/jest.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ function jestmock(name, mocker, { override = false } = {}) {
if (insideEsbuild) {
// esbuild handles unwrapping just default exports for us
assert(!likelyESM) // should not be reachable
const { default: defaultExport, __esModule, ...namedExports } = value // eslint-disable-line @typescript-eslint/no-unused-vars
// Don't override defaultExport, as that's processed with esbuild
// Add named exports though for further static named imports from that module
// type:module and esbuild can be combined e.g. when testing typescript packages
if (__esModule) obj.namedExports = namedExports
} else if (likelyESM && isObject(value) && value.__esModule === true) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { default: defaultExport, __esModule, ...namedExports } = value
Expand Down

0 comments on commit a7654cc

Please sign in to comment.