speedskater / babel-plugin-rewire

A babel plugin adding the ability to rewire module dependencies. This enables to mock modules for testing purposes.
842 stars 90 forks source link

__get__ returns functions that only have access to un-rewired values #192

Closed elliotbonneville closed 7 years ago

elliotbonneville commented 7 years ago

Values that have been rewired are not accessed by functions that are extracted via __get__. Instead, the original values are used.

Example code:

// mymodule.js
function foo(value) {
    console.log(`Hello ${value}`);
}

function bar(value) {
    foo(value);
}

Test:

import { __RewireAPI__ as ModuleRewireAPI } from 'mymodule';
ModuleRewireAPI.__Rewire__('foo', console.log);
ModuleRewireAPI.__get__('bar')('World');

Will result in an output of:

Hello World

When the expected output is:

World

elliotbonneville commented 7 years ago

Nevermind -- this is actually Mocha's fault. Closing!