-
Wanted to mock Is there a better solution other than replacing Describe 'root' {
it 'Symbol' {
{ mock '>' } | Should -Throw '*Could not find Command >*'
}
it 'Out-File' {
function redirect {
'text' > 'MyFake:\Path\Dir'
}
{ redirect } | Should -Throw '*Cannot find drive*'
mock 'Out-File' {
$InputObject
$LiteralPath
$FilePath
$args
}
# Can mock successfully, but cannot get any parameters.
(redirect) | Should -Be $null
Should -Invoke 'Out-File' -Exactly 1
}
}
|
Beta Was this translation helpful? Give feedback.
Answered by
fflaten
Sep 7, 2021
Replies: 1 comment 3 replies
-
Redirect operators aren't commands, but features in the language engine. You can't mock them. Mocking only works for commands that you can see with Can you say more about why you would need this? |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
Andy-AO
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Redirect operators aren't commands, but features in the language engine. You can't mock them. Mocking only works for commands that you can see with
Get-Command
.Can you say more about why you would need this?