问题描述
我正在执行集成测试,在这种情况下,我必须在表单数据中提供字段。我可以在.attach提供一个密钥和文件。就我而言,我必须在同一请求中的表单数据中提供五个键和值。如何实现?
我已经执行了示例代码。
const response = await request(server)
.post('url for the request')
.set({
'Content-Type': 'application/json',})
.attach('key','file');
解决方法
您可以使用.field()
添加其他基于文本的字段(有关更多详细信息,请参见docs)
const response = await request(server)
.post('url for the request')
.set({
'Content-Type': 'application/json',})
.field('category','Product')
.field('type','Image')
.field('category','Product')
.field('entity_no','12354')
.attach('file','/path/to/file');