Does Jest swallow console.log statements? Is there a way to change this?

后端 未结 5 1943
闹比i
闹比i 2021-02-11 17:14

Does Jest swallow console.log output?

// __tests__/log.test.js

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


        
5条回答
  •  梦如初夏
    2021-02-11 17:49

    I found a work around, despite the fact that sadly neither TERM=dumb, nor verbose: false nor upgrading to version 24 worked (I'm on 24.9). Just spy on the console, and you can see the results. Set it up with this:

    const consoleSpy = jest.spyOn(console, 'log')

    And then view the calls after running your tests using:

    consoleSpy.mock.calls[0][0]

提交回复
热议问题