Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

console.timeLog() not working in jest tests

Tags:

node.js

jestjs

When I start a simple jest test:

describe('console test', () => {
  it('console.logTime test', () => {
    // nocommit: https://stackoverflow.com/questions/58961221/console-timelog-not-working-in-nodejs-12
    console.log(process.version);

    console.time('process');
    for (let i = 0; i < 100000; i++) {}
    console.timeLog('process', 42);
    for (let i = 0; i < 100000; i++) {}
    console.timeEnd('process');
  });
});

I can see a warning that timeLog does not recognize the process label:

  console.log src/lib/rxjs/rxjs-util.spec.ts:67
    v12.12.0

  console.time src/lib/rxjs/rxjs-util.spec.ts:73
    process: 2ms

(node:17748) Warning: No such label 'process' for console.timeLog()

The example is almost the same as in the docs for timeLog().

Notes:

  • it works in nodejs (outside of jest tests)
  • jest version is 24.9.0

What am I missing here?

like image 919
TmTron Avatar asked Dec 03 '25 03:12

TmTron


1 Answers

As of jest v26.2.0 console.timeLog() is supported.

like image 84
webstech Avatar answered Dec 04 '25 22:12

webstech



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!