Closed vexx32 closed 5 months ago
Closing as not planned, this is easy to check by outputting the error from Should -Throw and doing any assertion you'd like on it.
$err = { throw [System.InvalidOperationException]::new() } | Should -Throw -PassThru
$err.Exception.GetType() | Should -BeIn @([System.InvalidCastException], [System.ArgumentException])
Expected collection @([System.InvalidCastException], [System.ArgumentException])
to contain [System.InvalidOperationException], but it was not found.
At S:\p\pester\src\functions\assertions\Should.ps1:252 char:13
+ throw $errorRecord
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidResult: (System.Collections.…ring,System.Object]:Dictionary`2) [], Exception
+ FullyQualifiedErrorId : PesterAssertionFailed
1. General summary of the issue
Currently,
Should -Throw -ExceptionType
only supports one type of exception being provided. In most cases, this works well, but for modules that need to be cross-platform and work with older versions of PS or .NET as well as recent versions, some exception types expected may differ depending on the version of .NET the module ends up running on.2. Describe Your Environment
N/A
3. Expected Behavior
Should -Throw
should support multiple exception types and/or messages to be provided to simplify tests that need to work on more than one version of PS / .NET.4.Current Behavior
Currently,
Should -Throw
only supports a single type name to be passed to-ExceptionType
(and-ExceptionMessage
).5. Possible Solution
One or both of these could be possible: