To mock requests for an API that expects a file as formData, there is no provision to add formData in CreateRequest method. When formData is added in CreateRequest, the module throws the following error:
Argument of type '{ method: "POST"; url: string; formData: { file: string; }; }' is not assignable to parameter of type 'RequestOptions'. Object literal may only specify known properties, and 'formData' does not exist in type 'RequestOptions'.
By using files option to send a file in the request, the API is unable to identify the file data as in an actual HTTP request the data is added in "file" object and not "files". The API under test expects a "file" parameter in formData. Internally, this API uses multer node module to read the file from formData. To know more about multer refer: multer
A sample HTTP request consisting of the formData looks as below:
formData: { file: { value: 'fs.createReadStream("video.txt")', options: { filename: 'video.txt', contentType: null } } }
There must be a way to send a file in formData in the mocked request.
To mock requests for an API that expects a file as formData, there is no provision to add formData in CreateRequest method. When formData is added in CreateRequest, the module throws the following error:
Argument of type '{ method: "POST"; url: string; formData: { file: string; }; }' is not assignable to parameter of type 'RequestOptions'. Object literal may only specify known properties, and 'formData' does not exist in type 'RequestOptions'.
By using files option to send a file in the request, the API is unable to identify the file data as in an actual HTTP request the data is added in "file" object and not "files". The API under test expects a "file" parameter in formData. Internally, this API uses multer node module to read the file from formData. To know more about multer refer: multer
A sample HTTP request consisting of the formData looks as below:
formData: { file: { value: 'fs.createReadStream("video.txt")', options: { filename: 'video.txt', contentType: null } } }
There must be a way to send a file in formData in the mocked request.