-
-
Notifications
You must be signed in to change notification settings - Fork 476
Closed
Description
BeforeAll and AfterAll do not work with script blocks (BeforeEach + AfterEach do not have this issue)
I tried this:
$beforeAllScriptBlock = [ScriptBlock]::Create("$PSScriptRoot\Tests\TestSetup.ps1")
BeforeAll { &$beforeAllScriptBlock }
but this failed with the message:
Invoke-Blocks : The expression after '&' in a pipeline element produced an object that was not valid. It must result in a command name, a script block, or a CommandInfo object.
At...
What I really wanted to be able to do was this:
Describe "foo" {
Context "bar" {
BeforeAll {
&"$PSScriptRoot\Tests\TestSetup.ps1"
}
It "Tests Something" {
........
}
}
}
the above fails to insert $PSScriptRoot (it's coming out blank in the error message)
I've tried a the [ScriptBlock]::Create
approach for BeforeEach and it works just fine.
I've added to the set of tests here that pass on Before/AfterEach and fail for Before/AfterAll: JonSutton@6edfa373fa3cae0940aee4c747e86add87734dea
Thanks!
Metadata
Metadata
Assignees
Labels
No labels