theKashey / rewiremock

The right way to mock dependencies in Node.js or webpack environment.
MIT License
491 stars 31 forks source link

Is it possible to make multiple hot mock updates? #125

Open s-maheshbabu opened 3 years ago

s-maheshbabu commented 3 years ago

Hot mock update appears to work the first time and only the first time. Is it possible to make multiple hot mock updates? Is the following expected to work?

rewiremock('./foo')
  .callThrough()
  .with({ action1: action1Stub1 })
  .dynamic();

 const foo = require('./foo');
 foo.action == action1Stub1;

 rewiremock.getMock('./foo')
   .with({ action1: action1Stub2 });
 foo.action == action1Stub2;

 rewiremock.getMock('./foo')
   .with({ action1: action1Stub3 });
 foo.action == action1Stub3;
theKashey commented 3 years ago

Not very sure about this operation - foo.action == action1Stub1;. It actually shall throw a little as there is no "set" operation defined at all.

Anyway - you've got a pretty simple use case, and the best I can do - create unit test from it. It will explain what is not working in the best possible way.

s-maheshbabu commented 3 years ago

I made a mistake with scopes. I was able to get multiple hot mock updates working just fine.

I will leave the issue open if you want to put a unit test in place but please consider this closed from my end. Thanks for building this library.