Open johlju opened 1 month ago
If I actually return $null
in the function Out-Something
then it works. π€
BeforeAll {
function Out-Something
{
param
(
)
$null
}
}
Describe 'Out-Something' {
It 'Should not output anything' {
$result = $null
$result = Out-Something
Write-Verbose ("Result is null: {0}" -f ($null -eq $result)) -Verbose
Write-Verbose ("Result is array: {0}" -f ($result -is [array])) -Verbose
$result | Should-BeNull
}
}
Returns:
Starting discovery in 1 files.
Discovery found 1 tests in 11ms.
Running tests.
VERBOSE: Result is null: True
VERBOSE: Result is array: False
[+] /Users/johlju/source/Viscalyx.Common/tests/Unit/Public/Out-Something.tests.ps1 420ms (5ms|405ms)
Tests completed in 421ms
Tests Passed: 1, Failed: 0, Skipped: 0, Inconclusive: 0, NotRun: 0
For some reason $result
is not actually $null
in the reproducible example, although the verbose statements says it is - but it is not... π€
This doesn't seem to be a Pester issue, but probably how PowerShell works... I just don't understand why it behaves as it does. If someone could shed som light it would be appreciated. π
Checklist
What is the issue?
I'm getting that the
$result
passed toShould-BeNull
is not$null
, but the verbose output I added to debug this do say it is not an array and it is indeed$null
. π€ Not sure if I'm doing something wrong. I have seen this in another place as well but ignored it there, when I got it here I thought this must be an error somewhere. πThe
Out-Diff
currently only writesWrite-Information
messages and returns no values. I output verbose message to determine that it is indeed $null and not an array, stillShould-BeNull
thinks it is.Expected Behavior
Should pass test as the actual value is $null.
Steps To Reproduce
Running this reproduces the issue:
Returns:
Describe your environment
Possible Solution?
Hopefully I'm just doing something wrong. π