How do you pass an entire array to an It block? #2131
Answered
by
fflaten
codykonior
asked this question in
Q&A
-
In the BeforeDiscovery block I'm setting up variables of lists of files to operate on. Then I have two different kinds of tests:
I can see how to do the first one in the examples:
But how do I do the second one? The closest I've come is to wrap it in an array again and then exclude the empty entry:
But it's pretty kludgy. Is there another way? |
Beta Was this translation helpful? Give feedback.
Answered by
fflaten
Feb 7, 2022
Replies: 1 comment
-
You won't get empty items with It "Blah" -ForEach (, $files) {
# Executes once with $_ equal to the original $files
} You could also use a hashtable as a wrapper. Each key will be available as a named variable in the test. It "Blah" -ForEach @{files = $files} {
# executes once. $files (key) contains the array. $_ contains the hashtable
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
nohwnd
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You won't get empty items with
(,$files)
, just an array with the files-array as first and only time.You could also use a hashtable as a wrapper. Each key will be available as a named variable in the test.