Evaluate Arrays with Pester getting 'not found'

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:test1@-project-accounts.iam.gserviceaccount.com', 'serviceAccount:sa-test2@test2.iam.gserviceaccount.com')
I assign that complete array to a variable to make it easier:
$testarray = @('serviceAccount:test1@-project-accounts.iam.gserviceaccount.com', 'serviceAccount:sa-test2@test2.iam.gserviceaccount.com')
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" InvalidResult: Line |1 | $testarray | Should -Contain "service" | Expected 'service' to be found in collection @('serviceAccount:test1@-project-accounts.iam.gserviceaccount.com', 'serviceAccount:sa-test2@test2.iam.gserviceaccount.com'), 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!

Thank you.

 

contain will not do a pattern match, instead it checks if “Service” is available in the array or not. You can try below


$testarray -match "Service" | Should -Be $True

Thank you so much sir! the -match works perfect! you save my life!