-
-
Notifications
You must be signed in to change notification settings - Fork 477
Checking a proper errors #673
Copy link
Copy link
Closed
Description
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" }Reactions are currently unavailable