nohwnd / Assert

A set of advanced assertions for Pester to simplify how you write tests.
MIT License
101 stars 12 forks source link

What is more useful Assert-Throw behavior? #15

Closed nohwnd closed 7 years ago

nohwnd commented 7 years ago

Assert throw will pass if any exception is thrown, but often we need to refine what exception we expected and what were it's properties. Which parameter is more useful to be provided by position? The type or the message?

# filter on message
{ throw [InvalidOperationException]"This is wrong!" } | Assert-Throw '*wrong*'
# filter on type
{ throw [InvalidOperationException]"This is wrong!" } | Assert-Throw ([InvalidOperationException])
brianbunke commented 7 years ago

I'd say string first, but no strong opinion.

mattmcnabb commented 7 years ago

I'd like to see both behaviors possible. You could filter on type primarily as this is similar to the pattern we use with try/catch. A second parameter should be available for filtering by message and further parameters for other exception properties.

nohwnd commented 7 years ago

In the end I did not make any of the paramater positional.

@mattmcnabb I just released it in 0.7.0. Please help me test it.