Pester
Pester copied to clipboard
Remove Mock fallthrough
PR Summary
Removes fallback to the mocked command. And replaces it with error message .
import-module .\bin\Pester.psd1 -force
Invoke-Pester -Container (New-PesterContainer -ScriptBlock {
Describe "a" {
It "b" {
function FunctionUnderTestWithoutParams () {}
Mock FunctionUnderTestWithoutParams { return "fake results" } -parameterFilter { $param1 -eq "test" -and $args[0] -eq 'notArg0' }
{ FunctionUnderTestWithoutParams -param1 "test" "arg0" } | Should -Throw "Mock felt though"
}
}
}) -Output Diagnostic
[-] b 3s (3s|3ms)
Expected an exception with message like 'Mock felt though' to be thrown, but the message was 'The mock for command 'FunctionUnderTestWithoutParams' did not match any filtered behavior, and there was no default behavior.
Performed ParameterFilter evaluations:
mock filter: { $param1 -eq "test" -and $args[0] -eq 'notArg0' } without any parameters
'. from S:\p\pester\src\functions\Mock.ps1:863 char:17
+ … throw "The mock for command '$($Hook.CommandName)' did no …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at { FunctionUnderTestWithoutParams -param1 "test" "arg0" } | Should -Throw "Mock felt though", untitled:Untitled-1:8
Fix #2178
The error message is pretty terrible. We will see it only when there is no default behavior, so there must be at least 1 paramtrized mock.
I tried to show what we evaluated in order to reach that point where no filter matched. but the wording needs to be better, and well as the formatting of the invoked filters I think.
But then we should be able to re-use similar thing for Should -Invoke to show the history of execution, when failing should Invoke. To show the performed invocations.