From f90741d82ad669986952fe605ce5c4c1373ddb48 Mon Sep 17 00:00:00 2001 From: OCram85 Date: Tue, 28 Jun 2022 14:48:05 +0200 Subject: [PATCH] try to mock private module function outside of module scope --- src/Private/Resolve-Dependency.Tests.ps1 | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Private/Resolve-Dependency.Tests.ps1 b/src/Private/Resolve-Dependency.Tests.ps1 index 5e3a9c6..7c3f2a1 100644 --- a/src/Private/Resolve-Dependency.Tests.ps1 +++ b/src/Private/Resolve-Dependency.Tests.ps1 @@ -13,8 +13,15 @@ BeforeAll { Describe "Resolve-Dependency" { Context "Basic syntax check" { - Mock Get-ModuleBase { return (Join-Path -Path $PWD -ChildPath '/resources') } -ModuleName 'PSCredentialStore' - Mock Test-Module { return $true } -ModuleName 'PSCredentialStore' + BeforeAll { + Mock -ModuleName 'PSCredentialStore' Get-ModuleBase { + return (Join-Path -Path $PWD -ChildPath '/resources') + } + Mock -ModuleName 'PSCredentialStore' Test-Module { + return $true + } + } + It "Test1: Should not throw" { { Resolve-Dependency -Name 'foobar2000' } | Should -Not -Throw } @@ -37,11 +44,16 @@ Describe "Resolve-Dependency" { } } Context "Testing input variations" { - Mock Get-ModuleBase { return (Join-Path -Path $PWD -ChildPath '/resources') } -ModuleName 'PSCredentialStore' It "Should return true if all given dependencies exist" { + Mock Get-ModuleBase { + return (Join-Path -Path $PWD -ChildPath '/resources') + } Resolve-Dependency -Name 'Existing' | Should -Be $true } It "Mixed results should return false" { + Mock Get-ModuleBase { + return (Join-Path -Path $PWD -ChildPath '/resources') + } Resolve-Dependency -Name 'PSGetMixed' | Should -Be $false } }