Force test to fail when stderr prints out stuffs #1948
-
Hi, is there a way we can force test to fail when stderr prints out something? For example I am using
but the test doesn't fail. |
Beta Was this translation helpful? Give feedback.
Answered by
sheremet-va
Sep 1, 2022
Replies: 1 comment 1 reply
-
You can do something like this, add to beforeEach((context) => {
context.failOnConsole = true // so you can modify this behaviour inside a test, if you don't want to fail
['log', 'warn', 'error'].forEach(method => {
vi.spyOn(console, method).mockClear()
})
})
afterEach((context) => {
if (!context.failOnConsole) return
['log', 'warn', 'error'].forEach(method => {
expect(console[method]).not.toHaveBeenCalled()
})
}) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
ahnpnl
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can do something like this, add to
test.setupFiles
: