Skip to content

Template placeholders not expanded the same way as in pester itself #247

@csandfeld

Description

@csandfeld

There is a mismatch between how placeholders are expanded in the "Pester Tests" (vscode-adapter) extension, and how they are expanded in Pester. I would expect them to be expanded the same by both.

As an example these tests ...

Template.tests.ps1

BeforeDiscovery {
    $arrayOfHashtables = @(
        @{ Emoji = '🌵' ; Description = 'cactus' }
        @{ Emoji = '🦒' ; Description = 'giraffe' }
        @{ Emoji = '🍎' ; Description = 'apple' }
        @{ Emoji = '🐧' ; Description = 'penguin' }
        @{ Emoji = '😊' ; Description = 'smiling face with smiling eyes' }
    )

    $arrayOfObjects = @(
        [pscustomobject]@{ Emoji = '🌵' ; Description = 'cactus' }
        [pscustomobject]@{ Emoji = '🦒' ; Description = 'giraffe' }
        [pscustomobject]@{ Emoji = '🍎' ; Description = 'apple' }
        [pscustomobject]@{ Emoji = '🐧' ; Description = 'penguin' }
        [pscustomobject]@{ Emoji = '😊' ; Description = 'smiling face with smiling eyes' }
    )
}


Describe 'Template expansion' {
    Context 'Array of hashtables' {
        It 'Using PropertyName:   Returns <Emoji> (<Description>)' -ForEach $arrayOfHashtables {}
        It 'Using _.PropertyName: Returns <_.Emoji> (<_.Description>)' -ForEach $arrayOfHashtables {}
    }

    Context 'Array of objects' {
        It 'Using PropertyName:   Returns <Emoji> (<Description>)' -ForEach $arrayOfObjects {}
        It 'Using _.PropertyName: Returns <_.Emoji> (<_.Description>)' -ForEach $arrayOfObjects {}
    }
}

... are expanded and rendered like this by the "Pester Tests" extension:

image

... whereas they are expanded and rendered like this by Pester:

image

PowerShell version (tested with PS5 as well)

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.4.1
PSEdition                      Core
GitCommitId                    7.4.1
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Pester Tests Extension version

Published
2023-07-31, 06:15:27
Last released
2023-08-01, 17:24:12
Last updated
2023-10-19, 19:25:47
Identifier
pspester.pester-test

Pester version

Get-Module -Name Pester

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     5.5.0                 Pester                              ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions