Closed sheppyh closed 3 months ago
In Pester BeforeEach
and AfterEach
are considered part of the test (It
scope). BeforeAll
and AfterAll
are part of the parent block.
See https://pester.dev/docs/usage/mocking#counting-mocks-depends-on-placement
Btw: I'd recommend defining mocks in a BeforeAll
to avoid overwriting it multiple times. Might be a shortcut for the repro but worth mentioning just in case.
Checklist
What is the issue?
The following code demonstrates the issue. The test "Should not invoke FunctionToBeMocked" fails.
If I remove the BeforeEach block from Describe, the "Should not invoke FunctionToBeMocked" test passes.
The test appears to ignore "-Scope It" and the invocation count is not reset.
Expected Behavior
The test should pass, as the scope of the Should -Invoke is set to "It".
Steps To Reproduce
Output:
Describe your environment
Pester version : 5.5.0 C:\Program Files\WindowsPowerShell\Modules\Pester\5.5.0\Pester.psm1 PowerShell version : 5.1.20348.2400 OS version : Microsoft Windows NT 10.0.20348.0
Possible Solution?
No response