Updated 2022-05-22 0
Viewed 11 times

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 
      if($array.thing -like *Example*) {
            $array | Add-Member -membertype NoteProperty -Name Match -Value $true
else {
    return 'fail'


Mock 'Function' {
    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