首页 > 其他 > 详细

[React Testing] Hide console.error Logs when Testing Error Boundaries with jest.spyOn

时间:2020-05-01 20:57:47      阅读:51      评论:0      收藏:0      [点我收藏+]

When testing an error boundary, your console will be filled with console.error calls from React. Those can be a real distraction from the rest of the output for your tests. Let’s clean those up with jest.spyOn.

 

beforeAll(() => {
  // do log out any error message
  jest.spyOn(console, error).mockImplementation(() => {})
})

afterAll(() => {
  console.error.mockRestore()
})

 

Then we can verify the console.error should be called in the test:

expect(console.error).toHaveBeenCalledTimes(2)

 

[React Testing] Hide console.error Logs when Testing Error Boundaries with jest.spyOn

原文:https://www.cnblogs.com/Answer1215/p/12814567.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!