我正在将测试从空手道 0.9.5 更新到 1.4.1。我们对属性可以为 null 的对象进行了很多模式验证测试,但这些测试在新版本的 Karate 中不起作用。
这是一个非常简单的示例,当子属性有内容时,它可以按预期工作。
* def nested = {'name': '#string'}
* def schema = {'sub': '##(nested)'}
Then match {'sub': {'name': 'I am here'}} == schema
我对空手道文档的理解是,
nested
上的##使其成为可选字段,但是当子属性为null
时,则此操作失败:
Then match {'sub': null} == '#(schema)'
我错过了什么?
是的,这种行为略有改变。这里解释了该怎么做:https://github.com/karatelabs/karate#remove-if-null
让我知道这现在是否适合您。
* def nested = {'name': '#string'}
* def schema = ({'sub': '##(nested)'})
* match { sub: { name: 123 } } == schema