1. General summary of the issue
When using a mock, you can specify a ParameterFilter. When the mock is being evaluated for whether or not it should be executed, a test is performed via Test-ParameterFilter. Unfortunately, this test just returns $true or $false which instructs Pester to not execute the mock and call the real function/cmdlet instead. However, there's no feedback as to why the parameter filter failed. In turn, this leads to less than useful error messages when the test fails.
2. Describe Your Environment
Pester version : 4.4.2 C:\Program Files\WindowsPowerShell\Modules\Pester\4.4.2\Pester.psd1
PowerShell version : 5.1.17134.165
OS version : Microsoft Windows NT 10.0.17134.0
3. Expected Behavior
I expect when I provide a parameter filter like: $Url -eq [Uri]::EscapeUriString($UrlSubstring), that when the parameter filter fails, a useful error message could be provided, such as:
Parameter filter test for mock for {cmdlet/function} with parameters {params} failed.
Expected: {expansion of $Uri}
Actual: {expansion of [Uri]::EscapeUriString(#UrlSubstring)
This would help in determining why one or mocks were not executed for the given parameters, making debugging tests (or code, for that matter) far easier. Instead, I had to troll through the debugger into Mock.ps1, Invoke-Mock, FindMock, and Test-ParameterFilter. On the bright side, I learned how the mocks work, which is quite cool, but most people shouldn't need to know that in order to get some useful information about why their tests are failing.
Also, when using Mock to create a mock, it would be helpful to get a reference to the mock back so we could "inspect" various aspects of it--or, perhaps, allow the ability to create Spies (or interception methods on the mock).
4.Current Behavior
Less than helpful messages are returned when no mocks are executed when verifying mocks.
5. Possible Solution
Add more internal state to the mocks (or the Pester State for the test?) that can be used for reporting back to Pester why a particular mock was not executed.
6. Context
See 1 and 3 above.
1. General summary of the issue
When using a mock, you can specify a
ParameterFilter. When the mock is being evaluated for whether or not it should be executed, a test is performed viaTest-ParameterFilter. Unfortunately, this test just returns$trueor$falsewhich instructs Pester to not execute the mock and call the real function/cmdlet instead. However, there's no feedback as to why the parameter filter failed. In turn, this leads to less than useful error messages when the test fails.2. Describe Your Environment
Pester version : 4.4.2 C:\Program Files\WindowsPowerShell\Modules\Pester\4.4.2\Pester.psd1
PowerShell version : 5.1.17134.165
OS version : Microsoft Windows NT 10.0.17134.0
3. Expected Behavior
I expect when I provide a parameter filter like:
$Url -eq [Uri]::EscapeUriString($UrlSubstring), that when the parameter filter fails, a useful error message could be provided, such as:This would help in determining why one or mocks were not executed for the given parameters, making debugging tests (or code, for that matter) far easier. Instead, I had to troll through the debugger into Mock.ps1, Invoke-Mock, FindMock, and Test-ParameterFilter. On the bright side, I learned how the mocks work, which is quite cool, but most people shouldn't need to know that in order to get some useful information about why their tests are failing.
Also, when using
Mockto create a mock, it would be helpful to get a reference to the mock back so we could "inspect" various aspects of it--or, perhaps, allow the ability to create Spies (or interception methods on the mock).4.Current Behavior
Less than helpful messages are returned when no mocks are executed when verifying mocks.
5. Possible Solution
Add more internal state to the mocks (or the Pester State for the test?) that can be used for reporting back to Pester why a particular mock was not executed.
6. Context
See 1 and 3 above.