Skip to content

Remove logging the origin line in Jest

Jest has this feature to log the line that outputs to console methods.

In some cases, this can become annoying:

  console.log _modules/log.js:37
  ℹ login.0 screenshot start

  console.time _modules/init.js:409
  login.0.screenshot: 0.33ms

  console.time _modules/init.js:394
  0 | login.0: 0.524ms

  console.log _modules/log.js:37
  ℹ login.1 screenshot start

Any idea how I can turn it off?

Advertisement

Answer

None of the above options worked for me.

The (current) simplest solution is this:

1: Create a file with this code (e.g. config.js)

import console from "console"
global.console = console

2: Add this line to your jest.config.js

setupFilesAfterEnv: ["./config.js"]

Before:

Remove logging the origin line in Jest

After:

Remove logging the origin line in Jest

Enjoi!

User contributions licensed under: CC BY-SA
4 People found this is helpful