Closed mmisztal1980 closed 1 year ago
@mmisztal1980 thanks for reporting the issue! Have you tried -TestCases
instead of -Foreach
?
Do you have a minimal reproduction I can look at?
For reference, this works fine and is in my current tests:
Describe 'Describe Nested Foreach <name> <symbol>' -ForEach @(
@{ Name = 'cactus'; Symbol = '🌵'; Kind = 'Plant' }
@{ Name = 'giraffe'; Symbol = '🦒'; Kind = 'Animal' }
) {
It 'Returns <symbol>' { $true }
It 'Has kind <kind>' { $true }
It 'Nested Hashtable TestCase <kind> <name>' { $true } -TestCases @{
Name = 'test'
}
It 'Nested Array TestCase <kind> <_>' { $true } -TestCases @(
'Test'
)
It 'Nested Multiple Hashtable TestCase <kind> <name> <symbol>' { $true } -TestCases @(
@{
Name = 'Pester1'
}
@{
Name = 'Pester2'
}
)
Context 'Context Nested Foreach <name> <ContextValue>' -ForEach @(
@{ ContextValue = 'Test1' }
@{ ContextValue = 'Test2' }
) {
It 'Describe Context Nested Array <name> <contextvalue> <_>' -TestCases @(
'Test1'
'Test2'
) { $true }
}
}
@mmisztal1980 I think actually it is because you have duplicate test names because you didn't use a variable in your foreach title description. The latest build now detects this and errors appropriately. Can you try the latest prerelease?
Hi Justin, I'm going to try this out today. Thanks for taking a look
@JustinGrote I don't see neither a new prerelease version of Pester nor of the VS Code Pester Tests
extension - where should I look?
I've added to placeholders to make the test cases' names unique, however I'm still seeing the issue.
I'm attaching the test-code (the parts that I can) https://gist.github.com/mmisztal1980/35b2ec0eecdd9dce40d6d6e337b4f063
Your example doesn't work in normal Pester either. It looks to me like your services
block either needs to be defined at script scope or in a BeforeAll
Here's an example that works for me (at least gets past the null index
BeforeAll {
[hashtable]$SCRIPT:services = @{
'NuGet' = 'SomeService';
'Paket' = 'SomePaketService';
}
}
Please check in the future that your Pester tests work fine with Invoke-Pester
run inside pwsh -noprofile
before filing an issue on the extension itself. Thanks!
Hmmm interesting. Any idea why is this behavior occuring?
Hmmm interesting. Any idea why is this behavior occuring?
https://pester.dev/docs/usage/discovery-and-run https://pester.dev/docs/usage/setup-and-teardown
I'm attempting to run pester tests from VSCode (for convenience). I've noticed that whenever I'm using
-ForEach
, the VSCode integration fails with :Cannot index into a null array.
error. This doesn't apply to regular tests.Pester Tests version:
v2023.7.7
Pester version: