Supertest: Test fails with .send and .attach - aka how do I send a token and upload an image/file in a test?

Created on 18 Jul 2016  路  4Comments  路  Source: visionmedia/supertest

It's killing me already. What am I doing wrong, or is this a legit bug?

My test w/out a token passes, and with fails. More precise details below.

https://stackoverflow.com/questions/38402244/how-to-unit-test-file-upload-with-supertest-and-send-a-token

Most helpful comment

@rafis It's been three years, but what gives you the right to say something like that? @lovelydreamer Can be just as good a developer as anyone can.

All 4 comments

(Nice photo, can't even believe you can be a nodejs developer.)
Seems you can not mix JSON body .send({}) with multipart form-data body .attach(), in that case the JSON will be ignored by supertest. Instead you can stick with multipart form-data and try this:

          .set('Accept', 'application.json')
          .field('token', config.token)
          .field('vehicle_vin', "randomVIN")
          .attach('file', '/Users/moi/Desktop/unit_test_extravaganza/hardwork.jpg')

wow so that really happened :| gross

@rafis It's been three years, but what gives you the right to say something like that? @lovelydreamer Can be just as good a developer as anyone can.

@rafis didn't know cats could be developers either 馃檮

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hacker0limbo picture hacker0limbo  路  3Comments

bookercodes picture bookercodes  路  5Comments

mayacr86 picture mayacr86  路  4Comments

NBNARADHYA picture NBNARADHYA  路  4Comments

jon301 picture jon301  路  5Comments