Skip to content

Should Not Throw filters suppresses exceptions when they don't match filter #953

@nohwnd

Description

@nohwnd

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...

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions