A Babel plugin that transforms internal references to a module's exports so they use `module.exports` instead of direct local variable references. This enables mocking of exported functions in Jest with Babel/TypeScript, even when those functions call each other internally within the same module. Version 1.0.2, actively maintained. Key differentiator: addresses the common problem of internal function references not being mockable in test environments, unlike other solutions that require manual refactoring or alternative mocking strategies.
npm install babel-plugin-explicit-exports-referencesVerified import paths — ran on the pinned version, not inferred.
Installs and configures the plugin to enable mocking of internal function references in Jest tests.
Only enable the plugin when NODE_ENV is 'test' using Babel's env configuration.
Do not rely on this plugin for mocking enum references; consider using modules or classes instead.
Avoid using { transformAssignExpr: true } unless absolutely necessary, and test thoroughly.If you need assignment expressions transformed, enable the experimental 'transformAssignExpr' option.
No fix needed; this is intended behavior as cross-module mocking is handled by Jest's module system.
Run 'npm install --save-dev babel-plugin-explicit-exports-references' to install the plugin.
Ensure the transformed code is processed by a bundler like Webpack that provides CommonJS compatibility, or only use in test environments with Jest.
Ensure 'explicit-exports-references' is in your babel.config.js under the 'test' environment and that Jest is using Babel for transformation.