Match each dosent fail for non existing json path

白昼怎懂夜的黑 提交于 2021-02-04 21:08:35

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!