I run the following test with Invoke-Pester. The 'function' tests fine but the 'workflow' fails. Is there any way for the test to see the calls within the InlineScript? Thanks.
BeforeAll {
function TestFunction {
Write-Host "Executing function"
Get-Host
}
workflow TestWorkflow {
InlineScript {
Write-Host "Executing inlinescript"
Get-Host
}
}
}
Describe "Test-Workflow" {
BeforeAll {
Mock Get-Host { "Mocked Get-Host" }
}
Context 'test' {
It 'workflow' {
TestWorkflow
Should -Invoke -Command Get-Host -Exactly 1
}
It 'function' {
TestFunction
Should -Invoke -Command Get-Host -Exactly 1
}
}
}
The test results:
[-] Test-Workflow.test.workflow 1.53s (1.53s|4ms)
Expected Get-Host to be called 1 times exactly, but was called 0 times
at Should -Invoke -Command Get-Host -Exactly 1, C:\Test-Workflow.Tests.ps1:25
at <ScriptBlock>, C:\Test-Workflow.Tests.ps1:25
Executing function
Tests completed in 1.97s
Tests Passed: 1, Failed: 1, Skipped: 0 NotRun: 0