rewire
rewire copied to clipboard
Doesn't work with `jasmine.clock()`
I found rewire doesn't work with jasmine.clock().
- Rewire a module uses
setTimeout() - Test the module with
jasmine.clock() jasmine.clock().tick()doesn't work
I made a sample to reproduce this here. Please see it :bow:
To be short:
module.exports = function () {
console.log(1);
setTimeout(function () {
console.log(2);
}, 100);
console.log(3);
};
When rewire above module and test it as below, the test fails.
jasmine.clock().install();
spyOn(console, 'log');
func();
jasmine.clock().tick(101);
expect(console.log).toHaveBeenCalledWith(2); // this fails
jasmine.clock().uninstall();
Of course when use require instead of rewire test passes correctly.
Hi, do you have a workaround for this?
@andreaazzara I use setTimeout() actually in my test code instead of jasmine.clock() for now. See here.
I did a PR with workaround. The solution is pretty simple I think
var rewire = require('rewire');
var rewireOptions = {
ignore: ['setTimeout']
};
var myModule = rewire('./myModule', rewireOptions);