Skip to content
Merged
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
7 changes: 0 additions & 7 deletions docs/additional-resources/misc.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ import { columns, integrations, books } from "./misc.table";
data={ books }
/>

## TBD

Waiting to be re-read and added

- [mikefrobbins.com](http://mikefrobbins.com/?s=pester)
- [powershell.org](https://powershell.org)

<PesterDataButton
text="Suggest New Entry"
editUrl="https://github.com/pester/docs/edit/main/docs/additional-resources/misc.table.js"
Expand Down
6 changes: 3 additions & 3 deletions docs/assertions/assertions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ Asserts that the collection contains value specified using PowerShell's -contain
Does not perform any comparison but checks if the object calling Exist is present in a PS Provider. The object must have valid path syntax. It essentially must pass a Test-Path call.

```powershell
$actual=(Dir . )[0].FullName
Remove-Item $actual
$actual | Should -Exist # Test will fail
Set-Content -Path TestDrive:\file.txt -Value 'I exist'
'TestDrive:\file.txt' | Should -Exist # Test will pass, the file exists
'TestDrive:\missing.txt' | Should -Exist # Test will fail, the file does not exist
```

To test a path that contains `[ ]` wildcards, use the `-LiteralPath` switch (added in Pester v6) so the path is treated literally instead of as a wildcard pattern:
Expand Down
32 changes: 13 additions & 19 deletions docs/assertions/custom-assertions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ When `Should` calls your custom assertion, it will invoke it with the following
- **ActualValue**: The value passed to `Should` to assert.
- **Negate**: Internal switch/bool parameter used to declare if the user called `Should -Not ...`.
- **CallerSessionState**: Used by some internal assertions to invoke code in the user's state. This can usually be ignored.
- *Remaining bound parameters*, typically matching the parameters your accept in your assertion, like `ExpectedValue`, `Because`, `MyCustomParameter` etc.
- *Remaining bound parameters*, typically matching the parameters you accept in your assertion, like `ExpectedValue`, `Because`, `MyCustomParameter` etc.

The function should return a object with the following properties:
The function should return an object with the following properties:
- **Succeeded**: Bool result of assert
- **FailureMessage**: Message to the user explaining why the assert failed, typically in the format `Expected <expected value>, but got <actual value>`. If the function supports the commonly used `-Because` parameter, this property should include that message.

Expand All @@ -37,11 +37,11 @@ Advanced functions, typically enabled by using `[CmdletBinding()]` or `[Paramete
- Support `-Not` for negative assertions. If not supported, throw an exception when used.
- Note that this is passed as `$Negate` to the function.
- Support `-Because` to let users customize the error message on failure.
- Write tests for you custom assertions to make sure they work the way you intended.
- Write tests for your custom assertions to make sure they work the way you intended.
- `Should` will create error records for failed assertions with the `FullyQualifiedErrorId` set to `PesterAssertionFailed`.
- Provide comment-based help with synopsis and examples so users can find it using `Get-ShouldOperator`.
- If you register an operator with a different name than the internal function, specify `-InternalName YourFunctionName` in `Add-ShouldOperator`.
This is required for `Get-ShouldOperator` to retrieve your comment-bases help.
This is required for `Get-ShouldOperator` to retrieve your comment-based help.

## Register function as operator

Expand All @@ -61,7 +61,7 @@ Add-ShouldOperator -Name BeNumber `
```

:::note Maximum number of Should operators
Due to a limitation in PowerShell and the current design on `Should`, Pester is limited to a maximum of 32 Should operators. Pester currently includes 25 built-in operators, which limits how many custom operators you can register in a single session.
Due to a limitation in PowerShell and the current design on `Should`, Pester is limited to a maximum of 32 Should operators. Pester currently includes 26 built-in operators, which limits how many custom operators you can register in a single session.
The limitation is tracked in [this issue](https://github.com/pester/Pester/issues/1355)
:::

Expand Down Expand Up @@ -140,15 +140,12 @@ Describe 'Testing Should -BeUpperCaseOnly' {
```powershell
Invoke-Pester ./demo.tests.ps1

Starting discovery in 1 files.
Discovery found 4 tests in 181ms.
Running tests.
[-] Testing custom assertion.Failure 22ms (20ms|3ms)
Running tests from 1 files.
[-] Testing Should -BeUpperCaseOnly.Failure 22ms
Expected 'HeLLo' to only contain uppercase letters because it looks cooler.
at "HeLLo" | Should -BeUpperCaseOnly -Because "it looks cooler", /workspaces/Pester/Samples/demo.tests.ps1:11
at <ScriptBlock>, /workspaces/Pester/Samples/demo.tests.ps1:11
at "HeLLo" | Should -BeUpperCaseOnly -Because "it looks cooler", C:\Pester\Samples\demo.tests.ps1:11
Tests completed in 651ms
Tests Passed: 3, Failed: 1, Skipped: 0 NotRun: 0
Tests Passed: 3, Failed: 1, Skipped: 0, Inconclusive: 0, NotRun: 0
```

### SupportsArrayInput example
Expand Down Expand Up @@ -220,13 +217,10 @@ Describe 'Testing Should -ContainOnlyValuesOf' {
```powershell
Invoke-Pester ./demo.tests.ps1

Starting discovery in 1 files.
Discovery found 2 tests in 25ms.
Running tests.
[-] Testing Should -ContainOnlyValuesOf.Failure 8ms (6ms|2ms)
Running tests from 1 files.
[-] Testing Should -ContainOnlyValuesOf.Failure 8ms
Expected values not equal to 3 to be in collection @(3, 3, 3).
at 3, 3, 3 | Should -Not -ContainOnlyValuesOf 3, /workspaces/Pester/Samples/demo.tests.ps1:11
at <ScriptBlock>, /workspaces/Pester/Samples/demo.tests.ps1:11
at 3, 3, 3 | Should -Not -ContainOnlyValuesOf 3, C:\Pester\Samples\demo.tests.ps1:11
Tests completed in 83ms
Tests Passed: 1, Failed: 1, Skipped: 0 NotRun: 0
Tests Passed: 1, Failed: 1, Skipped: 0, Inconclusive: 0, NotRun: 0
```
25 changes: 11 additions & 14 deletions docs/assertions/should-command.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ title: Should
description: Introduction to the Pester's built-in Should assertions which can be used to fail or pass a test
---

:::warning Work in progress 🛠️
This page is incomplete and will be updated as we get closer to release.
:::

## Overview

Pester includes a comprehensive set of assertions that you can use to either fail or pass a test.
Expand All @@ -15,15 +11,15 @@ In fact, Pester v6 actually includes two sets of assertions:
- All new `Should-*` assertions introduced in Pester v6, e.g. `Should-BeString`, `Should-BeTrue` etc.
- The `Should` command known from previous version of Pester, invoked using parameter sets like `Should -Be`, `Should -BeTrue` etc.

Both types of assertions are supported side-by-side in Pester v6, but we recommend your try out and migrate to the newer assertions.
Both types of assertions are supported side-by-side in Pester v6, but we recommend you try out and migrate to the newer assertions.

## `Should-*` assertions (v6)

Pester v6 comes with a new set of `Should-*` assertions that have been built from the ground up.
If you've previously tested the [`Assert`](https://github.com/nohwnd/assert)-module, these will be familiar.
Check out Command Reference in the sidebar to read more about the new assertions, e.g. [`Should-BeString`](../commands/Should-BeString.mdx).

These new assertions are split these categories based on their usage:
These new assertions are split into these categories based on their usage:

- [Value](#value-assertions)
- [Generic](#generic-value-assertions)
Expand Down Expand Up @@ -83,7 +79,7 @@ $null | Should-BeCollection -Expected $null

#### Using the -Actual syntax

The value provides to `-Actual`, is always exactly the same as provided.
The value provided to `-Actual` is always exactly the same as provided.

```powershell
Should-Be -Actual 1 -Expected 1
Expand Down Expand Up @@ -309,21 +305,22 @@ Describe "describe" {
```

```
Starting test discovery in 1 files.
Found 1 tests. 51ms
Test discovery finished. 83ms
Running tests from 1 files.

Running tests from 'C:\t\describe.Tests.ps1'
Describing describe
[-] user 124ms (109ms|15ms)
[-] user 124ms
[0] Expected strings to be the same, but they were different.
String lengths are both 5.
Strings differ at index 0.
Expected: 'Tomas'
But was: 'Jakub'
at $user.Name | Should -Be "Tomas"
^
at $user.Name | Should -Be "Tomas", C:\t\describe.Tests.ps1:15
[1] Expected 27, but got 31.
at $user.Age | Should -Be 27
at $user.Age | Should -Be 27, C:\t\describe.Tests.ps1:16
Tests completed in 286ms
Tests Passed: 0, Failed: 1, Skipped: 0, Total: 1, NotRun: 0
Tests Passed: 0, Failed: 1, Skipped: 0, Inconclusive: 0, NotRun: 0
```

This allows you to check complex objects easily without writing It for each of the properties that you want to test. You can also use `-ErrorAction Stop` to force a failure when a pre-condition is not met. In our case if `$user` was null, there would be no point in testing the object further and we would fail the test immediately.
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 @@ -35,7 +35,7 @@ description: Pester v5 included an all-new runtime which lead to some breaking c
### Additional issues to be solved future releases

- `-Strict` switch is not available
- Automatic Code coverage via -CI switch currently disabled as it's slow. Can still be enabled using configuraitonis largely untested.
- Automatic Code coverage via -CI switch currently disabled as it's slow. Can still be enabled using configuration, but is largely untested.


**Noticed more of them? Share please!**
4 changes: 2 additions & 2 deletions docs/migrations/v3-to-v4.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function Update-PesterTest {

.EXAMPLE

Update-PesterTest -Path .\Pester3-Tests\Dumy.Tests.ps1 .\Pester4-Tests\Dumy.Tests.ps1
Update-PesterTest -Path .\Pester3-Tests\Dummy.Tests.ps1 .\Pester4-Tests\Dummy.Tests.ps1

.NOTES
Original author
Expand Down Expand Up @@ -189,7 +189,7 @@ function Update-PesterTest {
if ($_.Value -eq 'Contain') {
$script = $script.Remove($_.Extent.StartOffset, 7).Insert($_.Extent.StartOffset, '-FileContentMatch')
} else {
$script = $script.Insert($_.Extent.Startoffset, '-')
$script = $script.Insert($_.Extent.StartOffset, '-')
}
}

Expand Down
2 changes: 1 addition & 1 deletion docs/migrations/v4-to-v5.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Consider settings the check statically into a global read-only variable (much li

# New result object

The new result object is extremely rich, and used by Pester internally to make all of its decisions. Most of the information in the tree is unprocessed to allow you to to work with the raw data. You are welcome to inspect the object, and write your code based on it.
The new result object is extremely rich, and used by Pester internally to make all of its decisions. Most of the information in the tree is unprocessed to allow you to work with the raw data. You are welcome to inspect the object, and write your code based on it.

To use your current CI pipeline with the new object use `ConvertTo-Pester4Result` to convert it. To convert the new object to NUnit report use `ConvertTo-NUnitReport` or specify the `-CI` switch to enable NUnit output, code coverage and exit code on failure.

Expand Down
43 changes: 15 additions & 28 deletions docs/quick-start.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,13 @@ This code uses multiple Pester keywords, and we will go over them in detail soon
In your console run `Invoke-Pester -Output Detailed C:\t\Planets\Get-Planet.Tests.ps1`:

```
Starting discovery in 1 files.
Discovering in C:\t\Planets\Get-Planet.Tests.ps1.
Found 1 tests. 41ms
Discovery finished in 77ms.
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 20ms (18ms|2ms)
[+] Given no parameters, it lists all 8 planets 20ms
Tests completed in 179ms
Tests Passed: 1, Failed: 0, Skipped: 0 NotRun: 0
Tests Passed: 1, Failed: 0, Skipped: 0, Inconclusive: 0, NotRun: 0
```

Looking at the last line of output you can see that we ran 1 test and it Passed. Good job, you just ran your first Pester test! 🥳🥳🥳
Expand Down Expand Up @@ -162,19 +159,15 @@ This will break the assertion that we have in our test, because we no longer ret
```
Invoke-Pester -Output Detailed C:\t\Planets\Get-Planet.Tests.ps1

Starting discovery in 1 files.
Discovering in C:\t\Planets\Get-Planet.Tests.ps1.
Found 1 tests. 9ms
Discovery finished in 21ms.
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 (12ms|7ms)
[-] 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
at <ScriptBlock>, C:\t\Planets\Get-Planet.Tests.ps1:22
Tests completed in 183ms
Tests Passed: 0, Failed: 1, Skipped: 0 NotRun: 0
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.
Expand All @@ -185,10 +178,9 @@ The change that we just did is not the only change that we can make to break the

```
Describing Get-Planet
[-] Given no parameters, it lists all 8 planets 25ms (21ms|4ms)
[-] 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
at <ScriptBlock>, C:\t\Planets\Get-Planet.Tests.ps1:21
Tests completed in 195ms
```

Expand Down Expand Up @@ -279,18 +271,16 @@ Describe 'Get-Planet' {
If we now run the test, we will see that it breaks, because the function is no longer reachable from the test:

```
Starting discovery in 1 files.
Discovering in C:\t\Planets\Get-Planet.Tests.ps1.
Found 1 tests. 14ms
Discovery finished in 36ms.
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 40ms (37ms|3ms)
CommandNotFoundException: The term 'Get-Planet' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
[-] Given no parameters, it lists all 8 planets 40ms
CommandNotFoundException: The term 'Get-Planet' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
at <ScriptBlock>, C:\t\Planets\Get-Planet.Tests.ps1:7
Tests completed in 214ms
Tests Passed: 0, Failed: 1, Skipped: 0 NotRun: 0
Tests Passed: 0, Failed: 1, Skipped: 0, Inconclusive: 0, NotRun: 0
```

The error is `CommandNotFoundException: The term 'Get-Planet' is not recognized as the name of a cmdlet, function, script file, or operable program.`. This is because the function is not defined, and we need to make it available to the test.
Expand All @@ -315,16 +305,13 @@ Describe 'Get-Planet' {
```
Invoke-Pester -Output Detailed C:\t\Planets\Get-Planet.Tests.ps1

Starting discovery in 1 files.
Discovering in C:\t\Planets\Get-Planet.Tests.ps1.
Found 1 tests. 19ms
Discovery finished in 31ms.
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 10ms (5ms|5ms)
[+] Given no parameters, it lists all 8 planets 10ms
Tests completed in 189ms
Tests Passed: 1, Failed: 0, Skipped: 0 NotRun: 0
Tests Passed: 1, Failed: 0, Skipped: 0, Inconclusive: 0, NotRun: 0
```

## Summary
Expand Down
6 changes: 3 additions & 3 deletions docs/usage/code-coverage.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Pester, offers a new way to configure Code Coverage using `New-PesterConfigurati

# Example output...
# Tests completed in 8.26s
# Tests Passed: 8, Failed: 0, Skipped: 0 NotRun: 0
# Tests Passed: 8, Failed: 0, Skipped: 0, Inconclusive: 0, NotRun: 0
# Processing code coverage result.
# Covered 11.7% / 75%. 735 analyzed Commands in 22 Files.
```
Expand Down Expand Up @@ -97,7 +97,7 @@ Invoke-Pester -Configuration $config
<#
...
Tests completed in 109ms
Tests Passed: 2, Failed: 0, Skipped: 0 NotRun: 0
Tests Passed: 2, Failed: 0, Skipped: 0, Inconclusive: 0, NotRun: 0
Processing code coverage result.
Covered 60% / 75%. 5 analyzed Commands in 1 File.
#>
Expand All @@ -117,7 +117,7 @@ Invoke-Pester -Configuration $config

<#
...
Tests Passed: 2, Failed: 0, Skipped: 0 NotRun: 0
Tests Passed: 2, Failed: 0, Skipped: 0, Inconclusive: 0, NotRun: 0
Processing code coverage result.
Code Coverage result processed in 22 ms.
Covered 60% / 75%. 5 analyzed Commands in 1 File.
Expand Down
10 changes: 3 additions & 7 deletions docs/usage/configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,7 @@ Describe "pester preference" {
```

```
Starting test discovery in 1 files.
Discovering tests in C:\Users\jajares\Desktop\mck.tests.ps1.
Found 1 tests. 44ms
Test discovery finished. 80ms

Running tests from 1 files.

Running tests from 'C:\Users\jajares\Desktop\mck.tests.ps1'
Describing pester preference
Expand All @@ -118,9 +114,9 @@ Mock: Finding all behaviors in this block and parents.
Verifiable: False
Mock: We are in a test. Returning mock table from test scope.
Mock: Removing function PesterMock_b0bde5ee-1b4f-4b8f-b1dd-aef38b3bc13d and aliases a for .
[+] mocks 857ms (840ms|16ms)
[+] mocks 857ms
Tests completed in 1.12s
Tests Passed: 1, Failed: 0, Skipped: 0, Total: 1, NotRun: 0
Tests Passed: 1, Failed: 0, Skipped: 0, Inconclusive: 0, NotRun: 0
```

## PesterConfiguration Options
Expand Down
Loading