From da3cbb94a42c903f466c4ca12fee49442df7bf5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Sat, 15 Aug 2026 20:10:57 +0200 Subject: [PATCH] Clarify when BeforeDiscovery runs The comment said "this will run during Discovery", and the name says before, so it reads as a contradiction. Reported in https://github.com/pester/Pester/discussions/2827 --- docs/usage/discovery-and-run.mdx | 2 +- versioned_docs/version-v5/usage/discovery-and-run.mdx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/usage/discovery-and-run.mdx b/docs/usage/discovery-and-run.mdx index 96557463..df31e79c 100644 --- a/docs/usage/discovery-and-run.mdx +++ b/docs/usage/discovery-and-run.mdx @@ -186,7 +186,7 @@ In this case the `foreach` is evaluated during `Discovery` because we simply run The example above has one more problem, if we move the setup to `BeforeDiscovery`, we will generate the tests correctly, and the `foreach` will define `$file` variable. But we won't be able to use the `$file` variable in the `It`. We need to attach it to the `It` using `-TestCases` with a single test case: ```powershell -BeforeDiscovery { # <- this will run during Discovery +BeforeDiscovery { # <- this runs in the Discovery phase, before the tests below are generated # check all script files $files = Get-ChildItem *.ps1 } diff --git a/versioned_docs/version-v5/usage/discovery-and-run.mdx b/versioned_docs/version-v5/usage/discovery-and-run.mdx index 200963a6..6ed6e862 100644 --- a/versioned_docs/version-v5/usage/discovery-and-run.mdx +++ b/versioned_docs/version-v5/usage/discovery-and-run.mdx @@ -147,7 +147,7 @@ In this case the `foreach` is evaluated during `Discovery` because we simply run The example above has one more problem, if we move the setup to `BeforeDiscovery`, we will generate the tests correctly, and the `foreach` will define `$file` variable. But we won't be able to use the `$file` variable in the `It`. We need to attach it to the `It` using `-TestCases` with a single test case: ```powershell -BeforeDiscovery { # <- this will run during Discovery +BeforeDiscovery { # <- this runs in the Discovery phase, before the tests below are generated # check all script files $files = Get-ChildItem *.ps1 }