Node.js 数组无意中被转换为具有supertest的对象
下面的数组(query.conditions)以某种方式转换为对象, 你知道我为什么以及如何预防它吗 请求:Node.js 数组无意中被转换为具有supertest的对象,node.js,supertest,Node.js,Supertest,下面的数组(query.conditions)以某种方式转换为对象, 你知道我为什么以及如何预防它吗 请求: supertest(options.url) .get('/api/action') .expect(200) .query({ conditions: [ { 'user' : user._id }
supertest(options.url)
.get('/api/action')
.expect(200)
.query({
conditions:
[
{ 'user' : user._id },
{ 'type' : 14 },
{ 'what' : 4 },
]
})
服务器获得的内容:
{
"conditions": {
"user": "5592cc851f3febd016dae920",
"type": "14",
"what": "4"
}
}
似乎在superagent
(由supertest
使用)中有
要解决此问题,您可以在数据上使用:
var qs = require('qs');
...
supertest(options.url)
.get('/api/action')
.expect(200)
.query(qs.stringify({
conditions:
[
{ 'user' : user._id },
{ 'type' : 14 },
{ 'what' : 4 },
]
}))
(如果可能的话,发布JSON可能更合适)