状态400:测试时无效的多部分有效负载格式

Tru*_*yen 5 payload supertest hapijs

我有这条路

server.route({
  method: 'POST',
  path: '/upload',
  config: {
    payload: {
      output: 'stream',
      parse: true,
      allow: 'multipart/form-data',
    },

    handler: fileUploadHandler
  }
})
Run Code Online (Sandbox Code Playgroud)

在浏览器上工作得很好; 但是,当通过jest + supertestpostman请求API时,Hapi返回状态400:无效的多部分有效载荷格式.我注意到的另一件事是甚至没有调用fileUploadHandler.

错误堆栈跟踪:

Error: Invalid multipart payload format
    at onError (/Users/trungnguyen/Desktop/bus-file-uploader/node_modules/subtext/lib/index.js:310:26)
    at g (events.js:291:16)
    at emitOne (events.js:101:20)
    at emit (events.js:188:7)
    at internals.Dispenser._emit (/Users/trungnguyen/Desktop/bus-file-uploader/node_modules/pez/lib/index.js:196:15)
    at internals.Dispenser._abort (/Users/trungnguyen/Desktop/bus-file-uploader/node_modules/pez/lib/index.js:202:10)
    at internals.Dispenser._onLineEnd (/Users/trungnguyen/Desktop/bus-file-uploader/node_modules/pez/lib/index.js:325:25)
    at _lines.on (/Users/trungnguyen/Desktop/bus-file-uploader/node_modules/pez/lib/index.js:94:14)
    at emitNone (events.js:86:13)
    at emit (events.js:185:7)
Run Code Online (Sandbox Code Playgroud)

这是我的Supertest(用Jest编写)代码:

  test('returns 500 if file is not CSV', async () => {
    await request(server.listener)
      .post('/upload')
      .attach('file', INVALID_EXTENSION_FILE)
      .expect(500);
  })
Run Code Online (Sandbox Code Playgroud)