Skip to content

Instantly share code, notes, and snippets.

@nohwnd
Created September 8, 2019 08:11
Show Gist options
  • Save nohwnd/58ff2f1b5864567290de052adabe0778 to your computer and use it in GitHub Desktop.
Save nohwnd/58ff2f1b5864567290de052adabe0778 to your computer and use it in GitHub Desktop.
Using ModuleName to test public surface of a module
Get-Module Pester, m | Remove-Module
Import-Module Pester -MaximumVersion 4.9.9
New-Module -Name m -ScriptBlock {
function a { "hello" }
function b { a }
Export-ModuleMember -Function b
} | Import-Module
Describe "m" {
It "can't see 'a'" {
{ a } | Should -Throw
}
It "but it can mock 'a'" {
Mock a -ModuleName m { "fuuuu" }
b | Should -Be "fuuuu"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment