1

I'm a bit perplexed why my tests are passing. I'm doing some assertions on what I believe the response should return. I'm getting a successful 200 status and an empty response. All the following assertions are passing though:

    When method get
    * print response
    Then status 200
    And match response == '#notnull'
    And match each $[*] == { caption : '#string' }
    And match each $[*] contains { source : '#object' }
    And match each $[*].source contains {channels : '#present' }
    And match each $[*] contains { post : '#object' }

Test output:

12:59:30.258 [main] INFO  com.dataminr.karate - [print] [
]

1 Scenarios (1 passed)
14 Steps (14 passed)
0m2.539s
drew2
  • 87
  • 1
  • 1
  • 9

1 Answers1

1

A match each will always pass on an empty array. Think of it like multiplying something by 0.

Just add this:

And match response != []

or:

And match response != '#[0]'
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • Appreciate it, Peter. I did add a check for ```And match response != []``` to fix it in my case, do you see any issues with that, or is the assertion you provided more reliable? – drew2 Mar 01 '19 at 16:16
  • Just want to make sure it's correct in case someone else pops along. But I think it should be ```And match response != '#[0]'``` before the other assertions? Having it as you've described will pass as well, and I'd like to catch it before it hits the match each. – drew2 Mar 01 '19 at 17:27