Fix Switch-Process error to include the command that is not found (#18443)

This commit is contained in:
Steve Lee authored and GitHub committed 2022-11-03 07:54:11 +05:00
1 parent 3e1a4d5679
commit 52a62e9ef2
3 files changed
+10 -3

No files matched your search

@@ -48,6 +48,13 @@ Describe 'Switch-Process tests for Unix' -Tags 'CI' {
($p | Get-Process).Name -eq 'sleep'
} -timeout 60000 -interval 100 | Should -BeTrue
}
It 'Error is returned if target command is not found' {
$invalidCommand = 'doesNotExist'
$e = { Switch-Process $invalidCommand } | Should -Throw -ErrorId 'CommandNotFound,Microsoft.PowerShell.Commands.SwitchProcessCommand' -PassThru
$e.Exception.Message | Should -BeLike "*'$invalidCommand'*"
$e.TargetObject | Should -BeExactly $invalidCommand
}
}
Describe 'Switch-Process for Windows' -Tag 'CI' {