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

Need documentation on $PesterBoundParameters and forwarding strategy #158

Closed
jazzdelightsme opened this issue Dec 13, 2021 · 3 comments · Fixed by #184
Closed

Need documentation on $PesterBoundParameters and forwarding strategy #158

jazzdelightsme opened this issue Dec 13, 2021 · 3 comments · Fixed by #184
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers

Comments

@jazzdelightsme
Copy link

I spent a lot of time trying to figure out how to do something pretty simple:

        Mock Copy-Item {
            $originalCopyItem = Get-Command Copy-Item -CommandType Cmdlet
            & $originalCopyItem @PesterBoundParameters
        }

There are actually two things here that I think should be documented:

  1. How to mock something, but still call the original something from within the mock; and
  2. How to generically forward parameters to that original thing (@PesterBoundParameters).

While not needed for most mocks, this is a valuable technique, and deserves to be mentioned somewhere.

@fflaten
Copy link
Collaborator

fflaten commented Dec 15, 2021

Thanks for the issue.

You're not really faking (mocking) the function anymore, but rather creating a proxy function.

I agree this could be easier to find though. I'm just not sure if this belongs as an example here or simply as a Q&A discussion in pester-repo or blog post promoted here as an edge case.

@jazzdelightsme
Copy link
Author

IMO, of those two places, I would say that the mocking page example is the better place. Because $PesterBoundParameters is a bona fide Pester feature, so I wouldn't expect to only be able to learn about it from a link to a blog somewhere. And maybe also on the reference page for the Mock command (mentioned as a special variable available to the script block passed via the -MockWith parameter).

@fflaten
Copy link
Collaborator

fflaten commented Dec 16, 2021

Sorry for not being precise. I was thinking about the first part only.

$PesterBoundParameters was new in 5.2.0 and should definitely be mentioned in multiple places as intended. 👍

@nohwnd nohwnd added documentation Improvements or additions to documentation good first issue Good for newcomers labels Apr 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants