如何匹配 JSON 数组中没有传递 NULL 的空字段 (' ') 的响应

How to match the reponse having empty fields(' ') which are not passing NULL in an JSON ARRAY

如何匹配具有不传递 NULL 的空字段 (' ') 的响应,如果我尝试 #notnull 匹配每个响应,脚本就会通过。但我在响应中看到几个空字段

如果您的服务器正在返回空格,但您想要将它们验证为空,那么您或服务器都错了。

就是说,您可以使用空手道轻松验证任何您想要的

* def isBlank = function(s){ return s ? ('' + s).trim() === '' : true }
* def foo = { bar: ' ' }
* match foo == { bar: '#? isBlank(_)' }

或者您甚至可以使用正则表达式:

* match foo == { bar: '#regex [ ]*' }

请参考文档。