Skip to main content
Version: v6 (preview) 🚧

BeforeDiscovery

This page was generated

Contributions are welcome in Pester-repo.

SYNOPSIS​

Runs setup code that is used during Discovery phase.

SYNTAX​

BeforeDiscovery [-ScriptBlock] <ScriptBlock> [<CommonParameters>]

DESCRIPTION​

Runs your code as is, in the place where this function is defined. This is a semantic block to allow you to be explicit about code that you need to run during Discovery, instead of just putting code directly inside of Describe / Context.

EXAMPLES​

EXAMPLE 1​

BeforeDiscovery {
$files = Get-ChildItem -Path $PSScriptRoot -Filter '*.ps1' -Recurse
}

Describe "File - <_>" -ForEach $files {
Context "Whitespace" {
It "There is no extra whitespace following a line" {
# ...
}

It "File ends with an empty line" {
# ...
}
}
}

BeforeDiscovery is used to gather a list of script-files during Discovery-phase to dynamically create a Describe-block and tests for each file found.

PARAMETERS​

-ScriptBlock​

The ScriptBlock to run.

Type: ScriptBlock
Parameter Sets: (All)
Aliases:

Required: True
Position: 1
Default value: None
Accept pipeline input: False
Accept wildcard characters: False

CommonParameters​

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS​

OUTPUTS​

NOTES​

https://pester.dev/docs/commands/BeforeDiscovery

https://pester.dev/docs/usage/data-driven-tests

VERSION​

This page was generated using comment-based help in Pester 6.0.0-alpha5.