Created
June 7, 2018 13:35
-
-
Save bgelens/903bfa921771ac66e336efd8653f6703 to your computer and use it in GitHub Desktop.
Have ErrorVariable populated through a Mock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Mock -CommandName Get-SomeCommand -MockWith { | |
param ( | |
$ErrorVariable | |
) | |
$errorRecord = [System.Management.Automation.ErrorRecord]::new( | |
[System.Exception]::new('Failed!'), | |
'Error', | |
[System.Management.Automation.ErrorCategory]::InvalidOperation, | |
$null | |
) | |
Set-Variable -Name $ErrorVariable -Value $errorRecord -Scope 3 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is what I came up with when testing a command that threw a non terminating error which populated ErrorVariable that changed the code flow. By having the mock setup like this, the ErrorVariable passed in is actually set.