- This topic has 2 replies, 2 voices, and was last updated 3 months, 2 weeks ago by
August 11, 2020 at 6:08 pm #248854ParticipantTopics: 1Replies: 1Points: 14Rank: Member
Hello Everyone! I am just a beginner with Pester and I am trying to evaluate some text for Unit Testing.
I have an array with two (2) items on it:
@(‘serviceAccount:[email protected]’, ‘serviceAccount:[email protected]’)
I assign that complete array to a variable to make it easier:
$testarray = @(‘serviceAccount:[email protected]’, ‘serviceAccount:[email protected]’)
when I try to make a powershell condition I obtain a ‘False’:
$testarray -contains “service”
Result -> False
And obviously if I try to make a Pester Assertion with Should I get an Invalidresult:
$testarray | Should -Contain “service”
Line |1 | $testarray | Should -Contain “service”
| Expected ‘service’ to be found in collection @(‘serviceAccount:[email protected]’, ‘serviceAccount:[email protected]’), but it was not found.
I am just trying to get a match with some text in the two values to get a ‘Test Pass’ but I am struggling with this for like 2 hours 🙁
If you need more information I can provide it!
August 12, 2020 at 2:31 pm #249131Senior ModeratorTopics: 9Replies: 1410Points: 5,236Rank: Community MVP
contain will not do a pattern match, instead it checks if “Service” is available in the array or not. You can try belowPowerShell12[crayon-5fbf53dbbf4cf958200868 inline="true" ]$testarray -match "Service" | Should -Be $True
August 12, 2020 at 4:58 pm #249149ParticipantTopics: 1Replies: 1Points: 14Rank: Member
Thank you so much sir! the -match works perfect! you save my life!
- The topic ‘Evaluate Arrays with Pester getting ‘not found’’ is closed to new replies.