Skip to content

Checking a proper errors #673

@iSazonov

Description

@iSazonov

In Powerhell Core project, we often use the following template for checking a proper errors:

it "Get-Item on a nonexisting file should have error PathNotFound" {
    try
    {
        get-item "ThisFileCannotPossiblyExist" -ErrorAction Stop
        throw "No Exception!"
    }
    catch
    {
        $_.FullyQualifiedErrorId | should be "PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand"
    }
}

It would be useful to implement something like:

{  get-item "ThisFileCannotPossiblyExist" -ErrorAction Stop } | Should Throw "PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand"

or

{  get-item "ThisFileCannotPossiblyExist" -ErrorAction Stop } | Should FullyQualifiedErrorId "PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand"

or

{  get-item "ThisFileCannotPossiblyExist" -ErrorAction Stop } | Should Throw { $_.FullyQualifiedErrorId -eq "PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand" }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions