I'm just getting set up with Jest and I've successfully written unit tests that test the DOM. I have a library that types things on the screen, so I'm able to test just fine. In some cases, instead of throwing an error, my library will spit out a console.warn
or console.log
. Is it possible to use Jest to test that these console messages are happening?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
You can set console.log to by a spy like this:
As your test file runs in a separate thread you don't need to reset
console
to the original methods