问题
I have json object in response. If I try an invalid path to extract value and assert it with match each it always passes.
* match each karate.jsonPath(response,"$[*].non.existing.path") == ["text1"]
Am I doing something wrong here?
Please Not: If I give correct path and the value doesn't match with 'text1' it fails. Absolutely no issue there. Seeing issue only with invalid json path.
回答1:
Yes, this is by design. match each
is actually a loop. If the number of items is zero, the match
will never be applied.
If you want to ensure that the array needs to be non-empty, add a second check.
* def foo = [1, 2]
* match foo == '#[_ > 0]'
* match each foo == '#number'
回答2:
I faced with a situation when my response had an empty array. When i matched it with any value it was passed. Example:
* match each array == '#(value)'
来源:https://stackoverflow.com/questions/60638091/match-each-dosent-fail-for-non-existing-json-path