Skip to content

Commit c7d48a5

Browse files
committed
Fix test for PowerShell 3.0 & 4.0
1 parent 45e6902 commit c7d48a5

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

Tests/Write-InformationLog.Tests.ps1

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,16 @@ InModuleScope ScriptLogger {
3434

3535
Mock Get-Date -ModuleName ScriptLogger { [DateTime] '2000-12-31 01:02:03' }
3636

37-
Mock Write-Information -ModuleName ScriptLogger -ParameterFilter { $MessageData -eq 'My Information' }
37+
if ($PSVersionTable.PSVersion -lt '5.0')
38+
{
39+
$InformationMockName = 'Write-Host'
40+
Mock $InformationMockName -ModuleName ScriptLogger -ParameterFilter { $Object -eq 'My Information' }
41+
}
42+
else
43+
{
44+
$InformationMockName = 'Write-Information'
45+
Mock $InformationMockName -ModuleName ScriptLogger -ParameterFilter { $MessageData -eq 'My Information' }
46+
}
3847

3948
BeforeAll {
4049

@@ -78,7 +87,7 @@ InModuleScope ScriptLogger {
7887

7988
Write-InformationLog -Message 'My Information'
8089

81-
Assert-MockCalled -CommandName 'Write-Information' -Times 1 -Exactly
90+
Assert-MockCalled -CommandName $InformationMockName -Times 1 -Exactly
8291
}
8392

8493
AfterEach {

0 commit comments

Comments
 (0)