bikk-uk / jest-mock-express

A lightweight Jest mock for unit testing Express
MIT License
50 stars 7 forks source link

How can I create a mock request with streaming support? #90

Open rampavandev opened 5 months ago

rampavandev commented 5 months ago

Hello,

I am writing an unit test for multipart form/data content. I would appreciate if there is a way to create a request with streaming so that I can pipe form content. Below is the code.

const form = new FormData()

form.append('meta', `{"DxDiagnosis":{"name":"dx mdef name"}}`)
form.append('file', fs.createReadStream('../../files/Dx_Diagnosis - Copy.csv'))

const req = mockRequest({
  method: 'POST',
  url: '/',
  headers: form.getHeaders(),
  user: {
    sub: 'cohortbuilder@iqvia.com',
    role: {
      name: 'Alerts Engine Admin',
    },
  },
})
aboyce commented 3 months ago

Can you post the test that you would want to see passing please.