-
-
Notifications
You must be signed in to change notification settings - Fork 479
Open
Milestone
Description
General summary of the issue
"Should -HaveParameter 'param' -Not -Mandatory" passes tests if parameter is not present
Describe your environment
Pester version : 5.3.1 C:\Users___\Documents\PowerShell\Modules\pester\5.3.1\Pester.psm1
PowerShell version : 7.2.0
OS version : Microsoft Windows NT 10.0.19043.0
Steps to reproduce
function hi {
param(
[parameter(mandatory)]
[string]$name
)
"hi $name"
}
Context 'ctx' {
It 'test missing param' {
$fnc = Get-Command 'hi'
$fnc | Should -HaveParameter 'anotherParam' -Not -Mandatory
}
}Context ctx
[+] test missing param 6ms (3ms|3ms)Expected Behavior
would expect the test to fail.
I can see how a parameter which is not declared is actually not mandatory. But i would still expect the 'Should -HaveParameter' to first check the actual presence of the parameter.
Current Behavior
test succeeds
Possible Solution? (optional)
use two tests
Context 'ctx' {
It 'test missing param' {
$fnc = Get-Command 'hi'
$fnc | Should -HaveParameter 'anotherParam'
$fnc | Should -HaveParameter 'anotherParam' -Not -Mandatory
}
} [-] test missing param 17ms (8ms|9ms)
Expected command hi to have a parameter anotherParam, but the parameter is missing.Metadata
Metadata
Assignees
Labels
No labels