How do I prevent Pester Mocked Read-Host from prompting for input during Code Coverage How do I prevent Pester Mocked Read-Host from prompting for input during Code Coverage powershell powershell

How do I prevent Pester Mocked Read-Host from prompting for input during Code Coverage


Given your use-case: Module Test-Foo function

function Test-Foo {    return (Read-Host -Prompt 'Enter value->')}

I would advise you to instead mock the Test-Foo function:

Context 'MyModule' {    Mock -ModuleName MyModule Test-Foo { return 'C:\example' }    It 'gets user input' {        Test-Foo | Should -Be 'C:\example'    }}