Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lovelydreamer opened this issue Jul 18, 2016 · 5 comments

Comments

@lovelydreamer
Copy link

lovelydreamer commented Jul 18, 2016

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

@rafis
Copy link

rafis commented Aug 5, 2016

(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')

@delprofundo
Copy link

wow so that really happened :| gross

@rimiti rimiti closed this as completed Feb 15, 2019
@eithermonad
Copy link

@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.

@joemckie
Copy link

joemckie commented Mar 1, 2020

@rafis didn't know cats could be developers either 🙄

@vitorgouveia
Copy link

@rafis would you please apologize to him?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants