Open raandree opened 1 year ago
I'm not confortable with pester, but my assumption is the code provided in the Get-PrivateFunction.tests.ps1
could not work for private functions.
The first lines are for loading the powershell module we are working on, but as it is a private functions, we can't call it.
$ProjectPath = "$PSScriptRoot\..\..\.." | Convert-Path
$ProjectName = ((Get-ChildItem -Path $ProjectPath\*\*.psd1).Where{
($_.Directory.Name -match 'source|src' -or $_.Directory.Name -eq $_.BaseName) -and
$(try { Test-ModuleManifest $_.FullName -ErrorAction Stop } catch { $false } )
}).BaseName
Import-Module $ProjectName
I think the solution would be to dot source the private function. This is where I am stuck now.
The test shpuld use InModuleScope
to access the private function.
It 'Should test something` {
InModuleScope -ModuleName 'MyModuleName' -ScriptBlock {
$result = Get-MyPrivateFunction
result | Should -Be 'MyResult'
}
}
As i understand Pester 5 syntax the Mock needs to go in BeforeEach, at least that is how i got it working with the module sample, so in Get-Something.tests.ps1 i added
Context 'Return values' { BeforeEach { Mock Get-PrivateFunction { $PrivateData } $return = Get-Something -Data 'value' }
The public and private functions tests are fixed in PR #439 and changed to support Pester 5. But there are more tests that has not been fixed yet. Must be fixed in other PRs.
Problem description
When creating a 'CompleteSample' with the command
Pester tests are failing with this error message
The issue is with the
Assert-MockCalled
calls. However, the allegedly missing mock is defined:Verbose logs
How to reproduce
Expected behavior
No failure when running the Pester tests.
Current behavior
see logs.
Suggested solution
NA
Operating system the target node is running
PowerShell version and build the target node is running
Module version used