0

every test I run produces 10 pages of pointless node-module stack traces. How do I get rid of them? I don't see this in the youtube testing videos, but I haven't found an answer after weeks.

mazoula
  • 1,221
  • 2
  • 11
  • 20
  • if you see a stack trace it usually means the code has crashed and the test runner catches this and tries the next test, so limit the test to 1 test and find the problem in your test code. Do all the tests pass? – rioV8 Sep 11 '22 at 09:30
  • Once I cleaned everything up it seems the dom was sending warnings about several unnecessary label properties. – mazoula Sep 11 '22 at 11:13
  • so it had nothing to do with the node-modules – rioV8 Sep 11 '22 at 11:15

1 Answers1

1

One way would be to just mock the console.log (or any console's method) out. Don't forget to keep the reference to the original method if you plan to restore it back for some other tests.

/** irreversible version */
console.log = jest.fn();

/** reversible version */
const logRef = console.log;

console.log = jest.fn();

// restore when needed
console.log = logRef;
Igor Bykov
  • 2,532
  • 3
  • 11
  • 19
  • why would a released node module output time consuming log statements, and in particular stack traces – rioV8 Sep 11 '22 at 09:35
  • @rioV8 DB logs transaction data, or Nest logs things about its start-up, or something logs errors that are expected, or anything really? – Igor Bykov Sep 11 '22 at 09:39
  • @rioV8 particularly, say you test a module that is supposed to throw on some invalid data but this module logs errors to `console.log` locally instead of logging them to an error reporting service in development – Igor Bykov Sep 11 '22 at 09:41
  • I had to mock console.error instead of console.log. I didn't know console.error was a thing. but the answer worked after that and possibly a vscode update. Also see here https://stackoverflow.com/questions/44596915/jest-mocking-console-error-tests-fails Thanks igor – mazoula Sep 11 '22 at 10:53