3

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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Moerwald
  • 10,448
  • 9
  • 43
  • 83

1 Answers1

6

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
        }
    }
}
Mark Wragg
  • 22,105
  • 7
  • 39
  • 68