Pester
Pester copied to clipboard
Add how to call original function to Mock help
Don't know what you do wrong, it works for me, when the function is in module and even if it is not in module:
New-Module a -ScriptBlock {
function My-Function () {
Write-Host "Hello"
}
} | Import-Module
Describe "Describe" {
Context "Context1 PASSES" {
Mock My-Function {
$myFunction = Get-Command My-Function -CommandType Function
return & $myFunction
}
My-Function
}
Context "Context2 FAILS" {
Mock My-Function {
$myFunction = Get-Command My-Function -CommandType Function
return & $myFunction
}
My-Function
}
}
This is latest Pester 4, which version are you using? This probably would not work on very old Pester where aliases are not used for Mocking, but instead of that functions are used.
Originally posted by @nohwnd in https://github.com/pester/Pester/issues/578#issuecomment-688762755
Indirectly covered in pester/docs#184