atecarlos / protractor-http-mock

A library designed to work alongside Protractor for setting up mocks for your HTTP ajax requests.
MIT License
173 stars 70 forks source link

feat(transformRequest): Support FormData in requests #72

Closed solcre closed 8 years ago

solcre commented 8 years ago

This feature allows to match a request that contains FormData. It requires to extend in FormData.prototype to keep track of appends in a property called "representation".

Sample code for extending FormData.prototype:

FormData.prototype.representation = {}; FormData.prototype._append = FormData.prototype.append; FormData.prototype.append = function(key, value) { this.representation[key] = value; this._append(key, value); };

BogdanLivadariu commented 8 years ago

some tests for this would be great

solcre commented 8 years ago

Added test here!

Please merge it!

BogdanLivadariu commented 8 years ago

Looks legit :+1:

atecarlos commented 8 years ago

Hi @solcre . Sorry for the delay. Could you provide more explanation on the ".representation" property?

atecarlos commented 8 years ago

Hi @solcre. I just read through the original issue you posted. I'm hesitant to add code into the plugin that only works with a workaround that I would suspect not many people will do.

I do like the idea of supporting FormData. Maybe we can work together for a solution that does not require the workaround? I'll look into this as soon as I can to see what other options are out there.

solcre commented 8 years ago

Hi @atecarlos, if you want to depend very little you could check if the FormData is fully implemented or partially by checking if get(), getAll() method are available. If they are not then the only possible solution to check if a value is set is the workaround I told you.

A better solution would be implement the missing methods by extending FormData similar to a polyfill. So when browsers starts implementing it no changes in the code would be needed. You will still need a property to keep track of appends.

Right now only Firefox 39 and Chrome with Experimental flag on support get and getAlll methods.

El Tuesday, March 1, 2016, atecarlos notifications@github.com escribió:

Hi @solcre https://github.com/solcre. I just read through the original issue you posted. I'm hesitant to add code into the plugin that only works with a workaround that I would suspect not many people will do.

I do like the idea of supporting FormData. Maybe we can work together for a solution that does not require the workaround? I'll look into this as soon as I can to see what other options are out there.

— Reply to this email directly or view it on GitHub https://github.com/atecarlos/protractor-http-mock/pull/72#issuecomment-191027507 .

[image: Solcre Technology Solutions]

Matias Fuster Coll Solcre Technology Solutions www.solcre.com +598 2706 9927 Ing. Luis P. Ponce 1443A 11602 Montevideo, Uruguay

BogdanLivadariu commented 8 years ago

@atecarlos you might want to restart the travis job, so it would pull in the latest changes & run the tests

atecarlos commented 8 years ago

@BogdanLivadariu I did restart the job. It keeps failing when running the selenium tests. It works just fine when executing on the master branch.

@solcre I understand the problem and the solution you are proposing. I still think we need to find a more generic option. Perhaps a polyfill, but it seems that might not be sufficient. For now, I don't think its a good move to merge this in, but I'm open to working together to find a more generic solution.