Skip to content

Can somebody explain the correct way to mock a 3rd party module function from another module #2070

Answered by fflaten
plastikfan asked this question in Q&A
Discussion options

You must be logged in to vote

The documentation only talks about mocking a function defined in the same module; ie A.do-action invoking A.do-task.

The docs show mocking/overriding an external command as part of the example code.

# Just for giggles, we'll also mock Write-Host here, to demonstrate that you can
# mock calls to commands other than functions defined within the same module.
Mock -ModuleName MyModule Write-Host {} -Verifiable -ParameterFilter {
    $Object -eq 'a build was run for version: 1.2'
}

The docs for Mock also tries to explain the meaning of ModuleName (same meaning in Mock and Should -Invoke).

-ModuleName
Optional string specifying the name of the module where this command is to be mocked. This …

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@plastikfan
Comment options

@plastikfan
Comment options

Answer selected by plastikfan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants