You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Should-InvokeInternal worker function is missing the $Because parameter. The Should-Invoke function does have the -Because parameter, and it turns around and passes it to Should-InvokeInternal by splatting in $PSBoundParameters:
$result= Should-InvokeInternal @PSBoundParameters
But that results in a ParameterBindingException:
Exception : System.Management.Automation.ParameterBindingException: A parameter cannot be found that matches parameter name 'Because'.
at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
at Should-Invoke(Closure , FunctionContext )
at System.Management.Automation.PSScriptCmdlet.RunClause(Action`1 clause, Object dollarUnderbar, Object inputToProcess)
at System.Management.Automation.CommandProcessorBase.Complete()
TargetObject :
CategoryInfo : InvalidArgument: (:) [Should-InvokeInternal], ParameterBindingException
FullyQualifiedErrorId : NamedParameterNotFound,Should-InvokeInternal
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at Should-Invoke, C:\Users\me\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1: line 14898
at Invoke-Assertion, C:\Users\me\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1: line 8070
at Should<End>, C:\Users\me\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1: line 8020
Describe your environment
Pester version : 5.3.1 C:\Users\danthom\Documents\PowerShell\Modules\Pester\5.3.1\Pester.psm1
PowerShell version : 7.2.1
OS version : Microsoft Windows NT 10.0.22523.0
Steps to reproduce
BeforeAll {
functionMyFunc { }
Mock MyFunc { }
}
Describe 'Repro' {
It 'should work' {
MyFunc
Should -Invoke -CommandName 'MyFunc'-Exactly 1-Because 'I called it'
}
}
Expected Behavior
Test should pass.
Current Behavior
ParameterBindingException: A parameter cannot be found that matches parameter name 'Because'.
Possible Solution? (optional)
My guess is the parameter just needs to be plumbed through.
The text was updated successfully, but these errors were encountered:
Feel free to submit a PR if you'd like to contribute the fix. Should be enough to add the parameter in the internal-function and include it in the message template somehow.
We should also consider to add Because to InvokeVerifiable (+ Internal) considering we do list the parameter as a good practice for assertions. Even though the error-messages are already long and complex in that assertion. 😬
General summary of the issue
The
Should-InvokeInternal
worker function is missing the$Because
parameter. TheShould-Invoke
function does have the-Because
parameter, and it turns around and passes it toShould-InvokeInternal
by splatting in$PSBoundParameters
:But that results in a ParameterBindingException:
Describe your environment
Steps to reproduce
Expected Behavior
Test should pass.
Current Behavior
ParameterBindingException: A parameter cannot be found that matches parameter name 'Because'.
Possible Solution? (optional)
My guess is the parameter just needs to be plumbed through.
The text was updated successfully, but these errors were encountered: