标签:led tin sts mock style you after col rac
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
标签:led tin sts mock style you after col rac
原文地址:https://www.cnblogs.com/Answer1215/p/12814567.html