【发布时间】:2018-07-16 11:18:12
【问题描述】:
我们正在尝试评估 Invoke-Command 是否被准确地调用过一次。
Script.ps1
Get-Job | Remove-Job
Invoke-Command -ScriptBlock {'test'} -ComputerName localhost -AsJob
Wait-Job
Get-Job | Reveive-Job
Script.Tests.ps1
Describe 'Test' {
Mock Invoke-Command {
# Mock here
}
It 'should be green' {
."$here\$sut" @Params
Assert-MockCalled -CommandName Invoke-Command -Times 1 -Exactly -Scope It
}
}
问题是在 Pester 中模拟作业对象。当作业没有被模拟时,Wait-Job 将抛出一个错误,它没有收到作业对象。
如何在Pester 中模拟 PowerShell 作业对象?
【问题讨论】:
标签: powershell mocking pester