Updated 2022-05-22 0
Viewed 11 times
0

Hey guys so I have this code (Powershell v5), and when I run the pester for it, the else statement is not being detected. Runs perfectly fine on powershell v7 but need it to run on v5. Source Code

Function 'INeedHelp'


$array= [Systems.Collections.ArrayList]::new()
$GettingInfo= #Function that's calling an object with properties
$String= 'Example'
$x= $null
$x= $GettingInfo | Where-Object { $._item -like "*$String*" -or $._ $thing like 
"*$String*"}
if($x){
      $array.Add($x)
      if($array.thing -like *Example*) {
            $array | Add-Member -membertype NoteProperty -Name Match -Value $true
      }      
}
else {
    return 'fail'
}

Pester

Mock 'Function' {
    return[PSCustomObject]@(
    item = 'hello'
    thing= 'bye'
    )
}
It 'Should be able to get the failure result'
$Result=  INeedHelp
$Result | Should -be 'fail'

The error is expected 'fail' but got @{item= 'hello'; thing= 'bye'}

🔴 No definitive solution yet