I have a PowerShell module which exports one cmdlet. The module contains several functions which are not visible to the end user. However, I want to test these functions via Pester (since the test setup will be simple).
Is it possible to call a non-exported function of a cmdlet? Or, is it possible to force module loading with all functions, though the psd1 file only exports some of them?
If you add an InModuleScope
block to your Pester script, you can then access private (non-exported) functions:
https://github.com/pester/Pester/wiki/InModuleScope
Import-Module MyModule
InModuleScope MyModule {
Describe 'Testing MyModule' {
It 'Tests the Private function' {
PrivateFunction | Should Be $true
}
}
}