I'm attempting to use Powershell to mock Join-Path with in a module. This mock will return a TestDrive location but I keep getting $null instead of the TestDrive location. In my example module $OutputPath returns with null. What am I doing wrong with my Mock?
foo.psm1
function foobar {
$OutputPath = Join-Path -Path $PSScriptRoot -ChildPath '..\..\..\Output\'
if (!(test-path $OutputPath) ) {
$null = New-Item -ItemType directory -Path $OutputPath
}
}
foo.Tests.ps1
import-module foo.psm1
Describe "Mock Example" {
$TestLocation = New-Item -Path "TestDrive:\Output\" -ItemType Directory
Mock -CommandName 'Join-Path' -MockWith { return $TestLocation.FullName } -ModuleName 'Foo' -ParameterFilter {$ChildPath -eq '..\..\..\Output\'}
}