ps/Modules/Alkami.PowerShell.Common/Public/Resolve-Error.tests.ps1
2023-05-30 22:51:22 -07:00

55 lines
1.4 KiB
PowerShell

. $PSScriptRoot\..\..\Load-PesterModules.ps1
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.tests\.', '.'
$functionPath = Join-Path -Path $here -ChildPath $sut
Write-Host "Overriding SUT: $functionPath"
Import-Module $functionPath -Force
$moduleForMock = ""
Describe "Resolve-Error" {
Context "Captures the error" {
It "Writes to Output" {
Mock -CommandName Write-Host -ModuleName $moduleForMock -MockWith {}
try {
throw "error"
} catch {
Resolve-Error
Assert-MockCalled -CommandName Write-Host -Scope It
}
}
}
Context "Should not throw" {
It "Parameter is throw safe" {
$e = New-Object System.Exception
{ Resolve-Error -ErrorRecord $e } | Should -not -Throw
}
It "Parameter position is throw safe" {
$e = New-Object System.Exception
{ Resolve-Error $e } | Should -not -Throw
}
}
Context "Should throw" {
It "Null parameter should throw" {
$e = $null
{ Resolve-Error -ErrorRecord $e } | Should -Throw
}
It "Null parameter position should throw" {
$e = $null
{ Resolve-Error $e } | Should -Throw
}
}
}