Skip to content

Commit

Permalink
Fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaunLawrie committed Mar 14, 2024
1 parent 4470fc7 commit 7598e81
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
17 changes: 9 additions & 8 deletions PwshSpectreConsole.Tests/prompts/Read-SpectrePause.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,28 @@ Describe "Read-SpectrePause" {
InModuleScope "PwshSpectreConsole" {
BeforeEach {
$testMessage = $null
Mock Write-SpectreHost {
if ($testMessage) {
$Message | Should -Be $testMessage
}
}
Mock Write-SpectreHost -Verifiable -ParameterFilter { $Message -eq $testMessage }
Mock Write-SpectreHost { }
Mock Clear-InputQueue
Mock Set-CursorPosition
Mock Write-Host
Mock Read-Host
Mock Read-ConsoleKey {
$enter = [System.ConsoleKey]::Enter
return [System.ConsoleKeyInfo]::new([char]$enter.value__, $enter, $false, $false, $false)
}
}

It "displays" {
Read-SpectrePause
Assert-MockCalled -CommandName "Read-Host" -Times 1 -Exactly
Assert-MockCalled -CommandName "Read-ConsoleKey" -Times 1 -Exactly
}

It "displays a custom message" {
$testMessage = Get-RandomString
Write-Debug $testMessage
Read-SpectrePause -Message $testMessage
Assert-MockCalled -CommandName "Read-Host" -Times 1 -Exactly
Assert-MockCalled -CommandName "Read-ConsoleKey" -Times 1 -Exactly
Should -InvokeVerifiable
}
}
}
3 changes: 3 additions & 0 deletions PwshSpectreConsole/private/Read-ConsoleKey.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function Read-ConsoleKey {
return [console]::ReadKey($true)
}
2 changes: 1 addition & 1 deletion PwshSpectreConsole/public/prompts/Read-SpectrePause.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function Read-SpectrePause {
}
Write-SpectreHost $Message -NoNewline
do {
$key = [console]::ReadKey($true)
$key = Read-ConsoleKey
if($AnyKey) {
break
}
Expand Down

0 comments on commit 7598e81

Please sign in to comment.