Skip to content

How would you test file upload ? #2250

Answered by RobinTail
JonathanCabezas asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @JonathanCabezas ,

Upload functionality relies on express-fileupload body parser which is not covered by the unit testing helper testEndpoint().
You can use testEndpoint with { requestProps: { method: "POST", body: data }} where data is already a parsed object, but that would be the test of the endpoint handler, not the parser, like the upload did already happen.

For testing the upload functionality you'd need a system test:

  1. Spawn a process running your application:
    const example = spawn("tsx", ["example/index.ts"]);
  2. Ensure it's listening (ready to accept requests):

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@JonathanCabezas
Comment options

Answer selected by RobinTail
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
good first issue Good for newcomers coverage Additional tests
2 participants