Closed kataik closed 4 years ago
Standard mockFactory
creates empty functions. Just mocks.
You might need to use more smart something, like sinon.spy or jest-mock - there is function to provide default implementation - .stubFactory
See example of usage - https://github.com/theKashey/rewiremock/blob/b13cd4b19660b6cb4570919b27a27450c63e97b1/_tests/mock.spec.js#L359-L364
Because you probably want to use stubs/spies and expectations provided by your framework, and I don't know what are they.
Thanks for the quick response. I actually did not expect it to define mocks/stubs for me, I do that separately. I was expecting it to implicitly add .callThrough()
to all .with(..)
and .withDefault(..)
calls.
Did I misunderstood the purpose of the plugin?
Probably. There are 3 behaviors:
.with
callThrough'. Keep all methods original, except the ones you overridden via
.with`mockThrough
. The same as above, but it "maps"(stubs) all original
stuff via stubsFactory
The default mode is the first one - do nothing you haven't asked for explicitly.
My bad, thanks for explaining! Great library!
Let's say I have a module I'd like to mock, which exports a class definition and a function as default:
When using the
mockThroughByDefault
plugin, it translates the exported classBar
into a constructor function which constructs an empty object. If I remove the plugin and callcallThrough()
directly, it works as expected:Again, if I replace the plugin with
callThrough()
, it yields (as expected):Test project: https://repl.it/repls/HeavyProfuseMaps