February 2019
Intermediate to advanced
626 pages
15h 51m
English
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 { BeforeAll { Mock Test-Path { ...Read now
Unlock full access