Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
3 tasks done
papadeltasierra opened this issue Aug 14, 2024 · 1 comment
Open
3 tasks done

Comments

@papadeltasierra
Copy link

Checklist

What is the issue?

Ref: #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
Copy link
Collaborator

fflaten commented Aug 22, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants