Skip to content

Can It blocks be used in BeforeAll/BeforeEach etc? #2132

Answered by nohwnd
codykonior asked this question in Q&A
Discussion options

You must be logged in to vote

You should not, it won't find the test, technically it is possible because tests run after BeforeAll. But having at least one test in the respective block is a pre-condition to run a BeforeAll at all. So even though I can make it work easily it by changing the internal test tree from BeforeAll, I did not pursue this idea further. So it is not supported and won't find your test.

Invoke-Pester -Container (New-PesterContainer -ScriptBlock {
    Describe "a" { 
        BeforeAll {
            It "a" {}
        }
        It "b" {}
    }
}) -Output Detailed
Pester v5.3.0

Starting discovery in 1 files.
Discovery found 1 tests in 6ms.
Running tests.
Describing a
  [+] b 4ms (1ms|3ms)
Tests compl…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by fflaten
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants