'Test the new Error() message with Cypress
I went over the documentation of cypress and i did not find any details about how to test if a error was thrown in javascript like:throw new Error('my error');
Question:
Is there a solution to test if a error wast thrown like i showed above, or to test the message?
Solution 1:[1]
Such an error is an Uncaught exception from your application
When Cypress detects an uncaught exception in your application, it will fail the currently running test.
You can turn off this behavior globally or conditionally with the uncaught:exception event. Please see the Catalog of Events for examples.
Cypress.on('uncaught:exception', (err, runnable) => {
expect(err.message).to.eq('my error')
return false
})
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | SuchAnIgnorantThingToDo-UKR |