Assert An Exception Is Raised
Last updated
Was this helpful?
Last updated
Was this helpful?
Elixir's comes with a number of different ways to make assertions in your tests. One of those functions is which allows you to test that a particular exception is raised when the given function is invoked.
Using assert_raise/2
looks something like this:
The assert_raise/3
form is also available which allows you to test both the type of exception and the resulting message.
Using the regex sigil for the second argument is generally a good way to go to keep tests from getting too brittle.