Skip to content

Proper method to handle nested loops? #2175

Answered by fflaten
PleaseStopAsking asked this question in Q&A
Discussion options

You must be logged in to vote

-ForEach/TestCases are evaluated during discovery, so you need to define the parameter-list in BeforeDiscovery. Related #1684

I'd also recommend to get function help once per command (Describe) only by using BeforeAll. BeforeEach runs before every test. Try:

BeforeDiscovery {
    $Cmdlets = Get-Command -Name Get-Item
}

Describe 'Help for <_>' -ForEach $Cmdlets {
    BeforeDiscovery {
        $Common = 'Debug', 'ErrorAction', 'ErrorVariable', 'InformationAction', 'InformationVariable', 'OutBuffer', 'OutVariable', 'PipelineVariable', 'Verbose', 'WarningAction', 'WarningVariable', 'Confirm', 'Whatif'

        $Command = $_ # Get current from -ForEach $Cmdlets in discovery-phase
        $Com…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@PleaseStopAsking
Comment options

Answer selected by PleaseStopAsking
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