pester / Pester

Pester is the ubiquitous test and mock framework for PowerShell.
https://pester.dev/
Other
3.08k stars 470 forks source link

Unable to use ParameterFilter on a Mock when the parameter is called Name #2556

Open papadeltasierra opened 1 month ago

papadeltasierra commented 1 month ago

Checklist

What is the issue?

Ref: https://github.com/pester/Pester/issues/1819 See my code below. The second Assert-MockCalled fails. This feels like the same bug as referenced above. Question:/ Should I be able to trace the parameter name in the Mock in the manner that I have done? $Name seems to be set to the value of the It block i.e. Debugging and if I change my Assert to check for $Name equal to Debugging then the Assert erroneously passes.

Expected Behavior

I expect this test to pass.

Steps To Reproduce

Describe 'My-Testing' {
    It 'Debugging' {
        Mock Get-AzureEnvironment {
            Write-Error -Message "Name: $Name" -ErrorAction Continue
            $context = [PSCustomObject]@{
                Name = "OutputName"
            }
            return $context
        }
        { Get-AzureEnvironment -Name "InputName" } | Should -Not -Throw
        Assert-MockCalled "Get-AzureEnvironment" -Times 1
        Assert-MockCalled "Get-AzureEnvironment" -Times 1 -ParameterFilter { $Name -eq "InputName" }
        Assert-VerifiableMock
    }
}

Describe your environment

Pester version : 5.6.1 C:\Users\pauldsmith\OneDrive - Microsoft\Documents\PowerShell\Modules\Pester\5.6.1\Pester.psm1 PowerShell version : 7.4.4 OS version : Microsoft Windows NT 10.0.22631.0

Possible Solution?

Possibly similar fix to the referenced issue?

fflaten commented 3 weeks ago

Thanks for the detailed report. I'm unable to reproduce the error. Did you try it in a fresh session and/or another machine? Which module and version did you use Get-AzureEnvironment from? I tested using module Azure v5.3.1.