匹配每个不存在的json路径的失败 [英] Match each dosent fail for non existing json path
问题描述
我有json对象作为响应.如果我尝试使用无效路径来提取值,并通过match对其进行断言,则始终会通过.
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?
请不要:如果我给出正确的路径并且该值与'text1'不匹配,则它将失败.那里绝对没有问题.仅看到无效的json路径问题.
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.
推荐答案
是的,这是设计使然. match each
实际上是一个循环.如果项目数为零,则match
将永远不会应用.
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'
这篇关于匹配每个不存在的json路径的失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!