小编sme*_*ten的帖子

超测多个 request.field 数组在服务器上未定义

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

编码:

//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
                }
Run Code Online (Sandbox Code Playgroud)

所以问题是服务器上的 req.body.tags 是未定义的。字符串没有问题。角度前端的实际实现运行良好,因此问题不在于服务器。

希望有人可以帮助我,在此先感谢...

arrays request mocha.js node.js supertest

1
推荐指数
1
解决办法
3271
查看次数

标签 统计

arrays ×1

mocha.js ×1

node.js ×1

request ×1

supertest ×1