Jest 会吞下 console.log 语句吗?有没有办法改变这种情况? [英] Does Jest swallow console.log statements? Is there a way to change this?

查看:21
本文介绍了Jest 会吞下 console.log 语句吗?有没有办法改变这种情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Jest 是否吞下 console.log 输出?

Does Jest swallow console.log output?

// __tests__/log.test.js

it('logs', () => {
  console.log('hey') // expect to see "hey" printed in terminal
})

// terminal output
$ jest --forceExit
PASS  __tests__/log.test.js
✓ logs (1ms) # where's "hey"?

我关心的主要原因是我正在写一些异步 beforeAllafterAll 的东西,我想使用 console.log 语句来调试事件的顺序.

The main reason I care is that I'm writing some async beforeAll and afterAll stuff, and I want to use console.log statements to debug the order of events.

推荐答案

这似乎是一个正在进行中问题.

使用 Node 10.7.0 和 Jest 23.4.1,将 verbose: false 添加到 jest 配置 (根据这个建议) 为我工作.

With Node 10.7.0 and Jest 23.4.1, adding verbose: false to the jest config (per this suggestion) worked for me.

编辑

现在我已经使用了 Jest 23.6,我还需要根据 Tamlyn 的回答将 TERM=dumb 作为环境变量传递.

Now that I've gone to Jest 23.6 I also need to pass TERM=dumb as an environment variable, per Tamlyn's answer.

这篇关于Jest 会吞下 console.log 语句吗?有没有办法改变这种情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆