I'm struggling a bit with the v5
Pester way of using mocks. Can anyone give me an example how I can verify that a specific mock was called via Should -InvokeVerifiable
? And also how I can check that a specific mock was called n-times.
I also checked following Pester docu Should InvokeVeriable, but didn't find an answer. Here I only found an example that invokes ALL mocks.
Example:
Describe "Describe " {
BeforeAll {
$localPsSession = New-PSSession -ComputerName "localhost"
# Arrange
Mock New-PSSession { $localPsSession } -Verifiable
Mock Remove-PSSession -Verifiable
# Act -> fire the function we want to test
...
}
It "Verify that Remove-PSSession was called in Act phase" {
# Here I want to check THAT only the Remove-PSSession mock was
# called and NOT the New-PSSession mock.
# Additionally I want to check that Remove-PSSession was called e.g. 3 times
Should -InvokeVerifiable
}
}