我创建了一个新的 Pester 夹具,并试图模拟对Get-Date
CmdLet 的调用,但它不起作用。如果我不使用它确实有效-ParameterFilter
。
假人.ps1
function dummy {
return Get-Date -f "dd"
}
dummy.Tests.ps1
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.'
. "$here\$sut"
Describe "dummy" {
Mock Get-Date { return "01" } -Verifiable -ParameterFilter {$f -match "dd"}
It "does something useful" {
dummy
Assert-VerifiableMocks
}
}
输出
Describing dummy
[-] does something useful 99ms
RuntimeException: Expected Get-Date to be called with $f -match "dd"
at Assert-VerifiableMocks, C:\Program Files\WindowsPowerShell\Modules\Pester\3.4.0\Functions\Mock.ps1: line 434
at <ScriptBlock>, E:\…\dummy.Tests.ps1: line 11
Tests completed in 99ms
Passed: 0 Failed: 1 Skipped: 0 Pending: 0 Inconclusive: 0
我尝试过使用-eq
而不是-match
for -ParameterFilter
,没有任何区别。
我觉得我必须在非常基本的层面上做错了什么,但看不到它 - 任何人都可以帮助我吗?
如果有任何区别,那就是在 Windows 10 虚拟机上;的输出$PSVersionTable
是:
Name Value
---- -----
PSVersion 5.1.14393.1198
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.1198
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1