-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
Potentially related: #2943
If a reporter uses console.log(), it should retain the function like we do with timers.
This will theoretically allow users to stub out console.log() in their own tests without affecting reporter output.
Since console.log() expects this to be console, it likely needs to take a form of:
const log = console.log.bind(console);process.stdout.write() may need to be consumed in a similar manner.
To reproduce the problem:
// yuck.spec.js
it('should do, but it do not', function() {
// user wants to hide output generated by console.log calls in fn 'foo'
console.log = function() {};
foo();
});Another approach would be to instantiate our own Console object (docs) which would bypass the global console entirely. We could consider subclassing Console in order to provide a nice abstraction for reporters consuming process.stdout directly (or other streams).
A workaround (for the user) would be to use something like proxyquire, rewiremock, etc. in lieu of replacing the method outright, like one would with Sinon.