Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/migrations/breaking-changes-in-v5.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ description: Pester v5 included an all-new runtime which lead to some breaking c
- PowerShell 2 is no longer supported
- Legacy syntax `Should Be` (without `-`) is removed, see [Migrating from Pester v3 to v4](./v3-to-v4)
- Mocks are scoped based on their placement, not in whole `Describe` / `Context`. The count also depends on their placement. See [mock scoping](../usage/mocking#mocks-are-scoped-based-on-their-placement)
- `Assert-VerifiableMocks` was removed, see [Should -Invoke](../usage/mocking#should--invoke)
- `Assert-VerifiableMocks` was removed, see [Should-Invoke](../usage/mocking#should-invoke)
- All code placed in the body of `Describe` outside of `It`, `BeforeAll`, `BeforeEach`, `AfterAll`, `AfterEach` will run during discovery and it's state might or might not be available to the test code, see [Discovery and Run](../usage/discovery-and-run)
- `-Output` parameter has reduced options to `None`, `Normal`, `Detailed` and `Diagnostic`. `-Show` alias is removed
- `-PesterOption` switch is removed
Expand Down
26 changes: 13 additions & 13 deletions docs/quick-start.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ BeforeAll {
Describe 'Get-Planet' {
It 'Given no parameters, it lists all 8 planets' {
$allPlanets = Get-Planet
$allPlanets.Count | Should -Be 8
$allPlanets.Count | Should-Be 8
}
}
```
Expand Down Expand Up @@ -114,23 +114,23 @@ Here are few examples:
```powershell
It 'Earth is the third planet in our Solar System' {
$allPlanets = Get-Planet
$allPlanets[2].Name | Should -Be 'Earth'
$allPlanets[2].Name | Should-Be 'Earth'
}
```

```powershell
It 'Pluto is not part of our Solar System' {
$allPlanets = Get-Planet
$plutos = $allPlanets | Where-Object Name -EQ 'Pluto'
$plutos.Count | Should -Be 0
$plutos.Count | Should-Be 0
}
```

```powershell
It 'Planets have this order: Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune' {
$allPlanets = Get-Planet
$planetsInOrder = $allPlanets.Name -join ', '
$planetsInOrder | Should -Be 'Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune'
$planetsInOrder | Should-Be 'Mercury, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune'
}
```

Expand Down Expand Up @@ -164,27 +164,27 @@ Running tests from 1 files.
Running tests from 'C:\t\Planets\Get-Planet.Tests.ps1'
Describing Get-Planet
[-] Given no parameters, it lists all 8 planets 19ms
Expected 8, but got 9.
at $allPlanets.Count | Should -Be 8, C:\t\Planets\Get-Planet.Tests.ps1:22
Expected [int] 8, but got [int] 9.
at $allPlanets.Count | Should-Be 8, C:\t\Planets\Get-Planet.Tests.ps1:22
Tests completed in 183ms
Tests Passed: 0, Failed: 1, Skipped: 0, Inconclusive: 0, NotRun: 0
```

The error is: `Expected 8, but got 9.`, this exactly reflects the change that we made to the tested function. We added one more item to the collection of planets, and the test confirms that the function is now broken.
The error is: `Expected [int] 8, but got [int] 9.`, this exactly reflects the change that we made to the tested function. We added one more item to the collection of planets, and the test confirms that the function is now broken.

### Breaking our test, by breaking the test expectation

The change that we just did is not the only change that we can make to break the test. There are other ways to do it. We can change the expected count to be 1, saying that there is just one planet orbiting the Sun, by changing the `Should` to `$allPlanets.Count | Should -Be 1`. This will also break the test:
The change that we just did is not the only change that we can make to break the test. There are other ways to do it. We can change the expected count to be 1, saying that there is just one planet orbiting the Sun, by changing the `Should` to `$allPlanets.Count | Should-Be 1`. This will also break the test:

```
Describing Get-Planet
[-] Given no parameters, it lists all 8 planets 25ms
Expected 1, but got 8.
at $allPlanets.Count | Should -Be 1, C:\t\Planets\Get-Planet.Tests.ps1:21
Expected [int] 1, but got [int] 8.
at $allPlanets.Count | Should-Be 1, C:\t\Planets\Get-Planet.Tests.ps1:21
Tests completed in 195ms
```

The error is: `Expected 1, but got 8.`, this again reflects exactly what we did in the test, but it no longer reflects the real world.
The error is: `Expected [int] 1, but got [int] 8.`, this again reflects exactly what we did in the test, but it no longer reflects the real world.

### How tests break

Expand Down Expand Up @@ -263,7 +263,7 @@ BeforeAll {
Describe 'Get-Planet' {
It 'Given no parameters, it lists all 8 planets' {
$allPlanets = Get-Planet
$allPlanets.Count | Should -Be 8
$allPlanets.Count | Should-Be 8
}
}
```
Expand Down Expand Up @@ -297,7 +297,7 @@ BeforeAll {
Describe 'Get-Planet' {
It 'Given no parameters, it lists all 8 planets' {
$allPlanets = Get-Planet
$allPlanets.Count | Should -Be 8
$allPlanets.Count | Should-Be 8
}
}
```
Expand Down
4 changes: 2 additions & 2 deletions docs/usage/code-coverage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ BeforeAll {

Describe 'Demonstrating Code Coverage' {
It 'Calls FunctionOne with no switch parameter set' {
FunctionOne | Should -Be 'SwitchParam was not set'
FunctionOne | Should-Be 'SwitchParam was not set'
}

It 'Calls FunctionTwo' {
FunctionTwo | Should -Be 'I get executed'
FunctionTwo | Should-Be 'I get executed'
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion docs/usage/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ BeforeAll {
Describe "pester preference" {
It "mocks" {
Mock a { "mock" }
a | Should -Be "mock"
a | Should-Be "mock"
}
}
```
Expand Down
38 changes: 19 additions & 19 deletions docs/usage/data-driven-tests.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Describe "Get-Emoji" {
@{ Name = "cactus"; Expected = '🌵'}
@{ Name = "giraffe"; Expected = '🦒'}
) {
Get-Emoji -Name $name | Should -Be $expected
Get-Emoji -Name $name | Should-Be $expected
}
}
```
Expand All @@ -39,11 +39,11 @@ The code above will generate tests that are equivalent to this:
```powershell
Describe "Get-Emoji" {
It "Returns 🌵 (cactus)" {
Get-Emoji -Name cactus | Should -Be '🌵'
Get-Emoji -Name cactus | Should-Be '🌵'
}

It "Returns 🦒 (giraffe)" {
Get-Emoji -Name giraffe | Should -Be '🦒'
Get-Emoji -Name giraffe | Should-Be '🦒'
}
}
```
Expand All @@ -60,7 +60,7 @@ Describe "Get-Emoji" {
@{ Name = "penguin"; Expected = '🐧'}
@{ Name = "smiling face with smiling eyes"; Expected = '😊'}
) {
Get-Emoji -Name $name | Should -Be $expected
Get-Emoji -Name $name | Should-Be $expected
}
}
```
Expand All @@ -75,11 +75,11 @@ Describe "Get-Emoji <name>" -ForEach @(
@{ Name = "giraffe"; Symbol = '🦒'; Kind = 'Animal' }
) {
It "Returns <symbol>" {
Get-Emoji -Name $name | Should -Be $symbol
Get-Emoji -Name $name | Should-Be $symbol
}

It "Has kind <kind>" {
Get-Emoji -Name $name | Get-EmojiKind | Should -Be $kind
Get-Emoji -Name $name | Get-EmojiKind | Should-Be $kind
}
}
```
Expand All @@ -89,21 +89,21 @@ Which is equivalent to writing:
```powershell
Describe "Get-Emoji cactus" {
It "Returns 🌵" {
Get-Emoji -Name cactus | Should -Be '🌵'
Get-Emoji -Name cactus | Should-Be '🌵'
}

It "Has kind Plant" {
Get-Emoji -Name cactus | Get-EmojiKind | Should -Be 'Plant'
Get-Emoji -Name cactus | Get-EmojiKind | Should-Be 'Plant'
}
}

Describe "Get-Emoji giraffe" {
It "Returns 🦒" {
Get-Emoji -Name giraffe | Should -Be '🦒'
Get-Emoji -Name giraffe | Should-Be '🦒'
}

It "Has kind Animal" {
Get-Emoji -Name giraffe | Get-EmojiKind | Should -Be 'Animal'
Get-Emoji -Name giraffe | Get-EmojiKind | Should-Be 'Animal'
}
}
```
Expand Down Expand Up @@ -133,17 +133,17 @@ Describe "Get-Emoji <name>" -ForEach @(
}
) {
It "Returns <symbol>" {
Get-Emoji -Name $name | Should -Be $symbol
Get-Emoji -Name $name | Should-Be $symbol
}

It "Has kind <kind>" {
Get-Emoji -Name $name | Get-EmojiKind | Should -Be $kind
Get-Emoji -Name $name | Get-EmojiKind | Should-Be $kind
}

Context "Runes (each character in multibyte emoji)" -ForEach $runes {
It "Has rune <rune> on index <index>" {
$actual = @((Get-Emoji -Name $name).EnumerateRunes())
$actual[$index].Value | Should -Be $rune
$actual[$index].Value | Should-Be $rune
}
}
}
Expand All @@ -156,19 +156,19 @@ Describe "Get-Emoji <name>" -ForEach @(
```powershell
Describe "Get-FruitBasket" {
It "Contains <_>" -ForEach '🍎','🍌','🥝','🥑','🍇','🍐' {
Get-FruitBasket | Should -Contain $_
Get-FruitBasket | Should-ContainCollection $_
}
}

Describe "Get-FruitBasket" {
Context "Fruit <_>" -ForEach '🍎','🍌','🥝','🥑','🍇','🍐' {
It "Contains <_> by default" {
Get-FruitBasket | Should -Contain $_
Get-FruitBasket | Should-ContainCollection $_
}

It "Can remove <_> from the basket" {
Remove-FruitBasket -Item $_
Get-FruitBasket | Should -Not -Contain $_
Get-FruitBasket | Should-NotContainCollection $_
}
}
AfterAll {
Expand Down Expand Up @@ -597,7 +597,7 @@ $name = "Jakub"

Describe "d" {
It "My name is: $name" {
$name | Should -be "Jakub"
$name | Should-Be "Jakub"
}
}
```
Expand All @@ -607,8 +607,8 @@ Running tests from 1 files.
Running tests from 'C:\p\g.Tests.ps1'
Describing d
[-] My name is: Jakub 106ms
Expected 'Jakub', but got $null.
at $name | Should -be "Jakub", C:\p\g.Tests.ps1:5
Expected [string] 'Jakub', but got [null] $null.
at $name | Should-Be "Jakub", C:\p\g.Tests.ps1:5
Tests completed in 436ms
Tests Passed: 0, Failed: 1, Skipped: 0, Inconclusive: 0, NotRun: 0
```
Expand Down
6 changes: 3 additions & 3 deletions docs/usage/discovery-and-run.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Describe "Get-Emoji" {
@{ Name = "cactus"; Expected = '🌵'}
@{ Name = "giraffe"; Expected = '🦒'}
) {
Get-Emoji -Name $name | Should -Be $expected
Get-Emoji -Name $name | Should-Be $expected
}
}

Expand Down Expand Up @@ -83,11 +83,11 @@ Container: Get-Emoji.Tests.ps1
Tests:
Test: Returns <expected> (<name>)
Data: @{ Name = "cactus"; Expected = '🌵'}
ScriptBlock: { Get-Emoji -Name $name | Should -Be $expected }
ScriptBlock: { Get-Emoji -Name $name | Should-Be $expected }

Test: Returns <expected> (<name>)
Data: @{ Name = "giraffe"; Expected = '🦒'}
ScriptBlock: { Get-Emoji -Name $name | Should -Be $expected }
ScriptBlock: { Get-Emoji -Name $name | Should-Be $expected }
```

Now we would go through all the objects, check filters and propagate them down and back up. This gives us the final overview of what needs to run. In this case there are no filters, so nothing changes and all tests will be invoked.
Expand Down
4 changes: 2 additions & 2 deletions docs/usage/importing-tested-functions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ $sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")

Describe "Get-Cactus" {
It "Returns 🌵" {
Get-Cactus | Should -Be '🌵'
Get-Cactus | Should-Be '🌵'
}
}
```
Expand All @@ -70,7 +70,7 @@ BeforeAll {

Describe "Get-Cactus" {
It "Returns 🌵" {
Get-Cactus | Should -Be '🌵'
Get-Cactus | Should-Be '🌵'
}
}
```
Expand Down
Loading