Specifying filters on Should Not Throw suppresses exception when it does not match the message. This does not make sense. The prerequisite for Should Not Throw is that no exception was thrown, the same way the pre requisite for Should Throw is that an exception was thrown.
get-module pester | Remove-Module ; Import-Module pester # -RequiredVersion 3.4.6
describe "a" { it "i" {
try {
{ throw "asdf" } | Should Not Throw "hello"
Write-Host "this should not be reached"
} catch { Write-Host "this should throw from the assertion ($_)" }
try {
{ throw "asdf" } | Should Not Throw
Write-Host "this should not be reached"
} catch { Write-Host "this should throw from the assertion ($_)" }
} }
# output
# this should not be reached
# this should throw from the assertion (Expected: Expected: the expression not to throw an exception...
Specifying filters on
Should Not Throwsuppresses exception when it does not match the message. This does not make sense. The prerequisite forShould Not Throwis that no exception was thrown, the same way the pre requisite forShould Throwis that an exception was thrown.