A Babel plugin that enables mocking of module dependencies for testing, based on the rewire.js concept. The current stable version is 1.4.0, with a release cadence that is maintenance-focused. It is a fork of babel-plugin-rewire with added TypeScript compatibility. Key differentiators: it works with TypeScript, supports ES6 imports, CommonJS require(), and named/top-level function rewiring. It provides a RewireAPI object for convenient mocking in tests. It is specifically designed for unit testing where module dependencies need to be replaced with mocks or stubs.
npm install babel-plugin-rewire-tsVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic setup and usage of babel-plugin-rewire-ts to mock a module dependency in tests.
Ensure that you reset dependencies after each test to avoid cross-test contamination.
Update test code to use __Rewire__ and __ResetDependency__ for consistency and proper external state handling.
Review tests that use __get__ to fetch internal state; after v1.4.0, the external state should reflect rewires, so __get__ might not be necessary.
Ensure that require() calls to be rewired are assigned to top-level variables in the module.
Ensure you have @babel/preset-typescript installed and configured in your Babel config.
Run npm install babel-plugin-rewire-ts --save-dev and check that it's listed in your Babel plugins.
Verify that babel-plugin-rewire-ts is included in your Babel config and that your test files are included in the Babel transformation.
No dependency data recorded yet.