-
I"m testing a PS module. In Pester v4 this worked, but migrating to v5 it appears my module is not loaded. #requires -Module F7History
Describe "f7_history" {
Context "The f7_history function" {
$cmd = $null
try {
$cmd = get-item -path Function:\f7_history
} catch {
$cmd = $null
}
It " is defined" {
$cmd | Should -Be "f7_history"
}
}
} > get-item -path Function:\f7_history
CommandType Name Version Source
----------- ---- ------- ------
Function f7_history 1.3.0.6 F7History
> invoke-pester -Path .\Tests\Public\
Starting discovery in 1 files.
Discovery found 4 tests in 90ms.
Running tests.
[-] f7_history.The f7_history function. is defined 14ms (10ms|4ms)
Expected 'f7_history', but got $null.
at $cmd | Should -Be "f7_history", C:\Users\charlie\s\gui-cs\F7History\Tests\Public\f7_history.Tests.ps1:13
at <ScriptBlock>, C:\Users\charlie\s\gui-cs\F7History\Tests\Public\f7_history.Tests.ps1:13 What am I missing? |
Beta Was this translation helpful? Give feedback.
Answered by
fflaten
Nov 4, 2023
Replies: 2 comments
-
In Pester v5 the setup code can't be loosely placed inside Describe/Context. You need to place it inside a BeforeAll or BeforeEach-block. See first section in the migration guide Try this: #requires -Module F7History
Describe "f7_history" {
Context "The f7_history function" {
BeforeAll {
$cmd = $null
try {
$cmd = get-item -path Function:\f7_history
} catch {
$cmd = $null
}
}
It " is defined" {
$cmd | Should -Be "f7_history"
}
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
tig
-
Got it. Thanks. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In Pester v5 the setup code can't be loosely placed inside Describe/Context. You need to place it inside a BeforeAll or BeforeEach-block.
See first section in the migration guide
Try this: