Evaluate Arrays with Pester getting ‘not found’

Welcome Forums Pester Evaluate Arrays with Pester getting ‘not found’

Viewing 2 reply threads
  • Author
    Posts
    • #248854
      Participant
      Topics: 1
      Replies: 1
      Points: 14
      Rank: 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”
      InvalidResult:
      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!

      Thank you.

       

    • #249131
      Senior Moderator
      Topics: 9
      Replies: 1309
      Points: 4,783
      Helping Hand
      Rank: Community Hero

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

      [/crayon]
      • This reply was modified 1 month, 1 week ago by kvprasoon. Reason: post correction
      • This reply was modified 1 month, 1 week ago by kvprasoon.
    • #249149
      Participant
      Topics: 1
      Replies: 1
      Points: 14
      Rank: Member

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

Viewing 2 reply threads
  • The topic ‘Evaluate Arrays with Pester getting ‘not found’’ is closed to new replies.