Parameter filters can be applied to mocks to limit the scope of the Mock.
A parameter filter is a script block that tests the parameters passed when the Mock is called. For example, a mock for Test-Path might only apply to a specific path:
Mock Test-Path { $true } -ParameterFilter { $Path -eq 'C:Somewhere' }
If Pester cannot find a Mock with a matching parameter filter, it will default to a mock without a parameter filter.
If there are no mocks available, the real command will be called. In the following example when the value of the Path parameter is C:, the value will be returned from the Mock. Otherwise, the value returned by the real command will be used:
Describe TestPathMocking { Mock Test-Path { $false } -ParameterFilter { $Path -eq 'C:' } It 'Uses the mock' { Test-Path 'C:' | Should -Be $false } It 'Uses the real command' { Test-Path 'C:Windows' | Should -Be $true } }