. $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 = "" #region Test-IsNull Describe "Legacy Test-IsNull" { Mock -ModuleName $moduleForMock Write-Warning -MockWith {} Context "When Value A is Null" { It "Returns Value B" { Test-IsNull $null "ValueB" | Should -Be "ValueB" } } Context "When Value A is an Empty String" { It "Returns Value B" { Test-IsNull "" "ValueB" | Should -Be "ValueB" } } Context "When Value A is Not Null" { It "Returns Value A" { Test-IsNull "ValueA" "ValueB" | Should -Be "ValueA" } } Context "When Value A is `$false" { It "Returns ValueB" { Test-IsNull $false "ValueB" | Should -Be "ValueB" } } Context "When Called Without Strict Parameter" { It "Warns The User They're Using An Old Version" { Test-IsNull "ValueA" "ValueB" Assert-MockCalled -CommandName Write-Warning -Times 1 -Exactly -Scope It -ModuleName $moduleForMock -ParameterFilter { $Message -match "You are using the old version of this function" } } } } Describe "Strict Test-IsNull" { Context "When Value A is Null" { It "Returns Value B" { Test-IsNull $null "ValueB" -Strict | Should -Be "ValueB" } } Context "When Value A is an Empty String" { It "Returns an Empty String" { Test-IsNull "" "ValueB" -Strict | Should -Be "" } } Context "When Value A is Not Null" { It "Returns Value A" { Test-IsNull "ValueA" "ValueB" -Strict | Should -Be "ValueA" } } Context "When Value A is `$false" { It "Returns Value A `$false" { Test-IsNull $false "ValueB" -Strict | Should -Be $false } } } #endregion Test-IsNull