weixin_39641257
weixin_39641257
2020-12-09 09:40

feat(transformRequest): Support FormData in requests

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); };

该提问来源于开源项目:atecarlos/protractor-http-mock

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

8条回答

  • weixin_39736606 weixin_39736606 5月前

    some tests for this would be great

    点赞 评论 复制链接分享
  • weixin_39641257 weixin_39641257 5月前

    Added test here!

    Please merge it!

    点赞 评论 复制链接分享
  • weixin_39736606 weixin_39736606 5月前

    Looks legit :+1:

    点赞 评论 复制链接分享
  • weixin_39721807 weixin_39721807 5月前

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

    点赞 评论 复制链接分享
  • weixin_39721807 weixin_39721807 5月前

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

    点赞 评论 复制链接分享
  • weixin_39641257 weixin_39641257 5月前

    Hi , 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.com escribió:

    Hi 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

    点赞 评论 复制链接分享
  • weixin_39736606 weixin_39736606 5月前

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

    点赞 评论 复制链接分享
  • weixin_39721807 weixin_39721807 5月前

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

    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.

    点赞 评论 复制链接分享

相关推荐