当我开始一个简单的 Jest 测试时:
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');
});
});
我可以看到 timeLog
无法识别 process
标签的警告:
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()
该示例与 timeLog() 的文档中的示例几乎相同.
注意事项:
- 它在 nodejs 中工作(在 jest 测试之外)
- jest 版本是
24.9.0
我在这里错过了什么?
最佳答案
自 jest v26.2.0 起支持 console.timeLog()
。
关于node.js - console.timeLog() 在 Jest 测试中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58961221/