作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我的 nodejs 服务器响应一个包含对象数组的对象,如下所示:
{
error: false
message: "get dispatchers successful"
data: [1]
0: {
id: 1
first_name: "Brenth Andrew J."
last_name: "Miras"
contact_number: null
email: "brenthmiras2@gmail.com"
address: null
image: null
password: "bajmiras"
created: "2014-09-12T10:24:06.000Z"
}
}
现在我想为数组数据的所有元素测试“数据”的属性类型。
我的飞盘测试是这样的:
//expect these types of response
.expectJSONTypes('*', {
error: Boolean,
message: String,
data: {
id: Number,
first_name: String,
last_name: String,
contact_number: String,
email: String,
address: String,
image: String,
password: String,
created: String
}
})
我得到这个错误:
TypeError: Expected '*' to be Array (got 'object' from JSON response)
我应该怎么做?
最佳答案
路径的每一段都由 分割。正如您可以在 frisby/lib/frisby.js 的源代码中找到的那样
_.each(path.split('.'), function(segment) {
所以做你的测试会是这样的:
.expectJSON('data.0', {last_name: "Miras"})
.expectJSONTypes('data.0', {
id: Number,
first_name: String
..
关于node.js - frisbyjs 对象数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25806946/
我的 nodejs 服务器响应一个包含对象数组的对象,如下所示: { error: false message: "get dispatchers successful" data: [1
我在另一个失败的 frisbyjs 测试的 afterJSON() 中有一个 frisbyjs 测试。当我调试服务器代码时,似乎没有发送 x-access-token 和 x-key HTTP hea
我正在测试对/abc/getme/login 的 POST 请求,其中 header 作为内容类型,并在正文中发送一个对象。我的代码如下: describe('HTTP Method Test for
我是一名优秀的程序员,十分优秀!