speedskater / babel-plugin-rewire

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

Not working as expected #145

Closed lblinovs closed 7 years ago

lblinovs commented 7 years ago

Assume I have this module structure:

function a() {
  return b();
}
...
function b() {
  return 'foo';
}

What I am doing:

import { __RewireAPI__ as foo } from 'foo/bar';
const baz = foo.__GetDependency__('a');
foo.__Rewire__('b', () => 'qux');

expect(baz()).to.equal('qux')

Expecting 'qux' but getting 'foo'.

speedskater commented 7 years ago

@lblinovs thanks for reporting this bug. I will try to have a look at it on the upcoming monday. It would be great if you could create a Sample with a failing PR (similar to the existing samples in the project).

speedskater commented 7 years ago

@lblinovs. Sorry for the delay. I have not actively worked on your issue till now, but created a new intermediate release. Could you please let me know if this improves the situation for you? If not. Could you please provide me a more detailed example (or a PR ;) ).

speedskater commented 7 years ago

@lblinovs I had a look at your issue. And unfortunately I think your issue won't be fixed. The reason is that you try to rewire a function which is never used, hence it doese not make sense to rewire it. If you have a valid use case for this exact usecase please don't hesitate to comment on this bug and we can try to achieve another solution, or if we have overseen something, we will try to tackle it.