diff --git a/PwshSpectreConsole.Tests/prompts/Read-SpectrePause.tests.ps1 b/PwshSpectreConsole.Tests/prompts/Read-SpectrePause.tests.ps1 index a0e7de0d..b9bcb0c3 100644 --- a/PwshSpectreConsole.Tests/prompts/Read-SpectrePause.tests.ps1 +++ b/PwshSpectreConsole.Tests/prompts/Read-SpectrePause.tests.ps1 @@ -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 } } } \ No newline at end of file diff --git a/PwshSpectreConsole/private/Read-ConsoleKey.ps1 b/PwshSpectreConsole/private/Read-ConsoleKey.ps1 new file mode 100644 index 00000000..2f02c861 --- /dev/null +++ b/PwshSpectreConsole/private/Read-ConsoleKey.ps1 @@ -0,0 +1,3 @@ +function Read-ConsoleKey { + return [console]::ReadKey($true) +} \ No newline at end of file diff --git a/PwshSpectreConsole/public/prompts/Read-SpectrePause.ps1 b/PwshSpectreConsole/public/prompts/Read-SpectrePause.ps1 index b04985ac..698a3cc8 100644 --- a/PwshSpectreConsole/public/prompts/Read-SpectrePause.ps1 +++ b/PwshSpectreConsole/public/prompts/Read-SpectrePause.ps1 @@ -39,7 +39,7 @@ function Read-SpectrePause { } Write-SpectreHost $Message -NoNewline do { - $key = [console]::ReadKey($true) + $key = Read-ConsoleKey if($AnyKey) { break }