Skip to content

ParameterBindingException when mocking Get-Package #2213

Description

@nyanhp

Checklist

What is the issue?

Mocking Get-Package results in ParameterBindingException. Get-Package is a compiled cmdlet, so I would assume that Pester should be able to mock it (unlike what happens in #619)

The error, as it appears:

[-] What.Is.Happening Here 66ms (65ms|1ms)
 ParameterBindingException: Parameter set cannot be resolved using the specified named parameters.
 at foo, <No file>:2
 at <ScriptBlock>, D:\tmp\bla.tests.ps1:15

Expected Behavior

The mock should be executed as expected and return "A Package" instead of throwing a ParameterBindingException

Steps To Reproduce

function foo {
    Get-Package -Name ThePackage
}
describe What {

    Context Is {
        BeforeAll {
            Mock -CommandName Get-Package -MockWith { return 'A Package' } -Verifiable -ParameterFilter { $Name -eq 'ThePackage' }
        }

        It 'Happening Here' {
            foo | Should -Be 'A Package'
        }

    }
}

Describe your environment

Pester version : 5.3.3 C:\Program Files\WindowsPowerShell\Modules\Pester\5.3.3\Pester.psm1
PowerShell version : 5.1.22000.653
OS version : Microsoft Windows NT 10.0.22000.0

Possible Solution?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions