Arrays 服务器上未定义Supertest multiple request.field数组

Arrays 服务器上未定义Supertest multiple request.field数组,arrays,node.js,request,mocha.js,supertest,Arrays,Node.js,Request,Mocha.js,Supertest,我正在用supertest编写一个单元测试来测试我的服务器。但是我的一个body字段包含一个json对象数组,未定义 守则: //declaration of variable tags = [{name: 'tag1'},{name: 'tag2'},{name: 'tag3'}]; //actual post agent.post('/pictures') .set('Connection', 'keep alive') .

我正在用supertest编写一个单元测试来测试我的服务器。但是我的一个body字段包含一个json对象数组,未定义

守则:

//declaration of variable
tags = [{name: 'tag1'},{name: 'tag2'},{name: 'tag3'}];

//actual post
 agent.post('/pictures')
                .set('Connection', 'keep alive')
                .set('Content-Type', 'application/x-www-form-urlencoded')
                .field('picTitle', 'Picture Title')
                .field('tags', tags)
                .attach('file', __dirname + '/img/noel.jpg')
                .end(function(pictureSaveErr, pictureSaveRes) {
                   //do stuff
                }
所以问题是服务器上的req.body.tags没有定义。字符串没有问题。使用angular frontend的实际实现工作正常,因此问题不在于服务器


希望有人能帮我,提前一声谢谢…

似乎是什么
字段
方法。因为它在引擎盖下使用模块。
您应该尝试以下方法:

agent.post('/pictures')
     .set('Connection', 'keep alive')
     .set('Content-Type', 'application/x-www-form-urlencoded')
     .field('picTitle', 'Picture Title')
     .field('tags[0][name]', tags[0].name)
     .field('tags[1][name]', tags[1].name)
     .field('tags[2][name]', tags[2].name)
     .attach('file', __dirname + '/img/noel.jpg')
     .end(function(pictureSaveErr, pictureSaveRes) {
         //do stuff
     }

似乎是什么
字段
方法。因为它在引擎盖下使用模块。
您应该尝试以下方法:

agent.post('/pictures')
     .set('Connection', 'keep alive')
     .set('Content-Type', 'application/x-www-form-urlencoded')
     .field('picTitle', 'Picture Title')
     .field('tags[0][name]', tags[0].name)
     .field('tags[1][name]', tags[1].name)
     .field('tags[2][name]', tags[2].name)
     .attach('file', __dirname + '/img/noel.jpg')
     .end(function(pictureSaveErr, pictureSaveRes) {
         //do stuff
     }

嗨,我也有同样的问题,但你的解决方案对我不起作用。有没有办法通过supertest发送数组?我已经使用
send
函数解决了这个问题。也许这对某些人会有帮助:
req.send({'CategoryID':'new','CategoryOrder':'15','CategoryName':{PL:'TestPL',EN:'TestEN'})此处的更多信息:放置requestsThanks,
.field('users[0]”,user1.\u id)
是否有效嗨,我也有同样的问题,但您的解决方案对我不起作用。有没有办法通过supertest发送数组?我已经使用
send
函数解决了这个问题。也许这对某些人会有帮助:
req.send({'CategoryID':'new','CategoryOrder':'15','CategoryName':{PL:'TestPL',EN:'TestEN'})此处的更多信息:放置requestsThanks,
.field('users[0]',user1.\u id)
起作用