Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

-HaveParameter: DefaultValue is always <empty> for alias #2290

Closed
3 tasks done
fflaten opened this issue Feb 1, 2023 · 1 comment · Fixed by #2353
Closed
3 tasks done

-HaveParameter: DefaultValue is always <empty> for alias #2290

fflaten opened this issue Feb 1, 2023 · 1 comment · Fixed by #2353
Labels
Assertions For issues related with assertions

Comments

@fflaten
Copy link
Collaborator

fflaten commented Feb 1, 2023

Checklist

What is the issue?

Should -HaveParameter alias123 -DefaultValue ... can't be used with aliases (AliasInfo). Will always say default-value is empty because.

Expected Behavior

Should be able to check a parameters default value when referencing command by alias.

Steps To Reproduce

function Test-Parameter {
    param (
        [Parameter()]
        [string]
        $Name = 'test'
    )
}
New-Alias t Test-Parameter
Get-Command -Name t | Should -HaveParameter 'Name' -DefaultValue 'test'

Describe your environment

Pester version : 5.3.3 C:\Users\Frode\Documents\PowerShell\Modules\pester\5.3.3\Pester.psm1
PowerShell version : 7.3.1
OS version : Microsoft Windows NT 10.0.22621.0

Possible Solution?

Check if inputobject is of type AliasInfo and try to get the function/script using ResolvedCommand. If empty, write warning or fail, but at least we tried.

@fflaten
Copy link
Collaborator Author

fflaten commented Feb 1, 2023

Or should we just say aliases are unsupported? You really should know (and use) the real function name when writing tests.

@fflaten fflaten added the Assertions For issues related with assertions label Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Assertions For issues related with assertions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant