Pester icon indicating copy to clipboard operation
Pester copied to clipboard

Improve error when -HaveParameter is used with mock or alias for local function

Open fflaten opened this issue 1 year ago • 1 comments

PR Summary

PowerShell doesn't resolve local functions properly for AliasInfo when function is defined in local scope in different session state. This affects use of -HaveParameter on a mocked command, ex. Get-Command Should -HaveParameter mockedCommand

Replace generic NRE with exception that suggests a workaround as this problem is unlikely to be fixed soon in PowerShell and probably not at all in Windows PowerShell.

Fix #1431

PR Checklist

  • [x] PR has meaningful title
  • [x] Summary describes changes
  • [x] PR is ready to be merged
    • If not, use the arrow next to Create Pull Request to mark it as a draft. PR can be marked Ready for review when it's ready.
  • [x] Tests are added/update (if required)
  • [ ] Documentation is updated/added (if required)

fflaten avatar Aug 08 '22 15:08 fflaten

Looking for feedback:

  • Throw vs failure message?
  • Should we stick with Where-Object Parameters workaround for both scenarios to keep it simple?

fflaten avatar Aug 08 '22 15:08 fflaten

Looks good, I would start from throwing, it is better to make the user correct their test, than us having to support yet another scenario where we "guess" for the user.

nohwnd avatar Oct 03 '22 08:10 nohwnd

Again pending comments. :/

nohwnd avatar Oct 31 '22 08:10 nohwnd

Pending #2267 to fix CI

fflaten avatar Nov 16 '22 17:11 fflaten

/azp run

fflaten avatar Dec 04 '22 13:12 fflaten

Azure Pipelines successfully started running 1 pipeline(s).

azure-pipelines[bot] avatar Dec 04 '22 13:12 azure-pipelines[bot]