Open
Description
Checklist
- Issue has a meaningful title
- I have searched the existing issues. See all issues
- I have tested using the latest version of Pester. See Installation and update guide.
What is the issue?
There is a great feature, where one can generate many tests based on an array of examples using -ForEach
or -TestCases
parameters. However, for the $null
case, the test does not get that $null
under $_
variable.
Expected Behavior
Generated parametrized test when executing should obtain given value under $_
- i.e. $true
when test cases array contains $true
, a 42
if there is that number, and the $null
when list contains that.
Moreover, templated name of it, should present $null
(or something "meaningful") and not System.Collections.Hashtable
as currently. I'm not sure if the $null
is the-correct-name, as currently -ForEach
renders simple values like:
@()
->
- a little bit "unmeaning"@{}
->System.Collections.Hashtable
$null
->System.Collections.Hashtable
$true
/$false
->True
/False
- which is how PowerShell prints them, but it's kind of inconsistent with how (e.g.)
Should -BeTrue
renders them as:Expected $true, but got $false.
- which is how PowerShell prints them, but it's kind of inconsistent with how (e.g.)
Steps To Reproduce
Have a test like this one:
Describe "Pester 'ForEach' support" {
It "provides `$_ with '<_>'" -ForEach @($null) {
$null -eq $_ | Should -BeTrue
}
}
Then, when executed:
Running tests from 'C:\Users\domin\Test.Tests.ps1'
Describing Pester 'ForEach' support
[-] provides $_ with 'System.Collections.Hashtable' 15ms (6ms|10ms)
Expected $true, but got $false.
at $null -eq $_ | Should -BeTrue, C:\Users\domin\Test.Tests.ps1:3
at <ScriptBlock>, C:\Users\domin\Test.Tests.ps1:3
Tests completed in 141ms
Tests Passed: 0, Failed: 1, Skipped: 0 NotRun: 0
Describe your environment
Pester version : 5.4.0 C:\Users\domin\Documents\PowerShell\Modules\Pester\5.4.0\Pester.psm1
PowerShell version : 7.3.3
OS version : Microsoft Windows NT 10.0.19044.0
Possible Solution?
No response