Closed Krinkle closed 3 years ago
We could capture and cache a reference to console.log
early on and use that, although that makes testing our own output harder since then we can't mock our own console anymore when testing TapReporter whilst using TapReporter. We could workaround that by exposing our cached reference in a pseudu-private property that we can still mock manually.
Alternatively, a bit more elaborate but perhaps cleaner method, is to give TapReporter a constructor parameter with a Writable stream. When used normally, that would default to process.stdout
(the Writable stream that console.log uses), and under test we can inject our own instance that we can easily mock.
Ref https://github.com/qunitjs/qunit/issues/1340.
If a project is mocking
console.log
because the project in question is, like js-reporters, also related to producing output, then at times it can make the test output broken and very hard to debug.