如何在空手道 1.4 中验证具有可为空属性的架构

问题描述 投票:0回答:1

我正在将测试从空手道 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)'

我错过了什么?

karate
1个回答
0
投票

是的,这种行为略有改变。这里解释了该怎么做:https://github.com/karatelabs/karate#remove-if-null

让我知道这现在是否适合您。

* def nested = {'name': '#string'}
* def schema = ({'sub': '##(nested)'})
* match { sub: { name: 123 } } == schema
© www.soinside.com 2019 - 2024. All rights reserved.