pester / docs

Source files for the Pester website.
https://pester.dev
MIT License
41 stars 77 forks source link

Syntax errors in Quick-Start Creating a Pester Test #289

Closed KyleRemil closed 5 months ago

KyleRemil commented 1 year ago

Checklist

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.

  1. The BeforeAll command may only be used inside a Describe block.
  2. RuntimeException: '-Be' is not a valid Should operator
  3. 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"

fflaten commented 1 year ago

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: