数组bellow(query.conditions)以某种方式转换为对象, 知道为什么以及如何阻止它?
请求:
supertest(options.url)
.get('/api/action')
.expect(200)
.query({
conditions:
[
{ 'user' : user._id },
{ 'type' : 14 },
{ 'what' : 4 },
]
})
服务器获取的内容:
{
"conditions": {
"user": "5592cc851f3febd016dae920",
"type": "14",
"what": "4"
}
}
答案 0 :(得分:4)
superagent
中似乎有issues with query string serialization(由supertest
使用)。
要解决此问题,您可以对数据使用qs.stringify()
:
var qs = require('qs');
...
supertest(options.url)
.get('/api/action')
.expect(200)
.query(qs.stringify({
conditions:
[
{ 'user' : user._id },
{ 'type' : 14 },
{ 'what' : 4 },
]
}))
(如果可能的话,可能更适合POST JSON)