Skip to content
unknown edited this page Feb 11, 2013 · 1 revision

Testing Exceptions

Sometimes you need to test a case where you expect the action to throw an exception. To do that, pass a script block to Should Throw:

{ Call-ScaryFunction } | Should Throw

Should Throw will eat the pipeline output and the exception and assert that an exception was thrown.

You can also test that the exception matches a particular pattern by adding a pattern after Throw:

{ Call-ScaryFunction } | Should Throw "egad"

Clone this wiki locally