Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pester test non-exported PowerShell cmdlets/function

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?

like image 772
Moerwald Avatar asked Nov 02 '25 20:11

Moerwald


1 Answers

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
        }
    }
}
like image 81
Mark Wragg Avatar answered Nov 04 '25 12:11

Mark Wragg