Syntax errors in Quick-Start Creating a Pester Test
Checklist
- [X] Issue has a meaningful title
- [X] I have searched the existing issues. See issues
Link to page
https://pester.dev/docs/quick-start
What is the issue?
I copy pasted the code into a document named Get-Planet.Tests.ps1 and got syntax errors.
- The BeforeAll command may only be used inside a Describe block.
- RuntimeException: '-Be' is not a valid Should operator
- Parameter cannot be processed because the parameter name 'Output' is ambiguous
I first removed 'BeforeAll' then I got the '-Be' exception. Either I don't understand the directions or the syntax is incorrect for the version I am running.
My PC: Windows 10 22H2 Pester 3.4.0 PowerShell 5.1.19041.3570
Suggested fix?
Update example code to:
function Get-Planet ([string]$Name = '*') { $planets = @( @{ Name = 'Mercury' } @{ Name = 'Venus' } @{ Name = 'Earth' } @{ Name = 'Mars' } @{ Name = 'Jupiter' } @{ Name = 'Saturn' } @{ Name = 'Uranus' } @{ Name = 'Neptune' } ) | ForEach-Object { [PSCustomObject] $_ }
$planets | Where-Object { $_.Name -like $Name }
}
Describe 'Get-Planet' { It 'Given no parameters, it lists all 8 planets' { $allPlanets = Get-Planet $allPlanets.Count | Should -Be 8 } }
Run in terminal with: Invoke-Pester "C:\MyFolder\Get-Planet.Tests.ps1"
Thanks for trying out Pester.
The docs at https://pester.dev are written for the latest version which currently is 5.5.0. You may also select v4 docs using the dropdown next to the Pester-logo in the top left.
Pester v3 is unsupported so the only docs available atm. are the included PowerShell command help and about_* files which you can read with ex. Get-Help about_Pester
I'd recommend that you upgrade to the latest v5 version using Install-Module Pester -Force -SkipPublisherCheck for new projects. For existing projects, see our migration guides:
- https://pester.dev/docs/migrations/v3-to-v4
- https://pester.dev/docs/migrations/v4-to-v5