weixin_39732866
weixin_39732866
2020-12-09 13:36

Breaks $http.defaults.transformRequest

When using this npm module, $http.defaults is undefined. Therefore calls like:

transformRequest: transformations.concat($http.defaults.transformRequest)

are broken.

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

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

11条回答

  • weixin_39559369 weixin_39559369 5月前

    I have a similar problem with $http.defaults being undefined. This solves it https://github.com/azevedo-252/protractor-http-mock/commit/8bded9139030cc94b1c59333c8e3aa8f547184fd

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

    Hi . Did that fix solve the problem for you? I can add it to the main branch.

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

    Hi, I haven't tried, I had to finish my test suite without using your library. But I will try. However, it does exactly what is needed, copies $http.defaults, so it should be fine. Will let you know.

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

    Thanks !

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

    within my environment ( Mac ) it is not running:

    Fatal error: protractor exited with code: 8

    npm ERR! protractor-http-mock.1.4 example: grunt example npm ERR! Exit status 3 npm ERR! npm ERR! Failed at the protractor-http-mock.1.4 example script. npm ERR! This is most likely a problem with the protractor-http-mock package, npm ERR! not with npm itself. npm ERR! Tell the author that this fails on your system: npm ERR! grunt example npm ERR! You can get their info via: npm ERR! npm owner ls protractor-http-mock npm ERR! There is likely additional logging output above. npm ERR! System Darwin 14.0.0 npm ERR! command "node" "/usr/local/bin/npm" "run" "example" npm ERR! cwd /Users/gertjanschoemaker/Downloads/protractor-http-mock-2cb1b5ade65fe7ce08a348ff19b5c7acf3d1fd78 npm ERR! node -v v0.10.33 npm ERR! npm -v 1.4.28 npm ERR! code ELIFECYCLE npm ERR! npm ERR! Additional logging details can be found in: npm ERR! /Users/gertjanschoemaker/Downloads/protractor-http-mock-2cb1b5ade65fe7ce08a348ff19b5c7acf3d1fd78/npm-debug.log npm ERR! not ok code 0

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

    Hi . Are you able to run other protractor tests from your computer? Can you provide any further information in the form of logs to help you debug the issue?

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

    First of all, great module . I love the fact that you don't need to modify the app's source (e.g. include a reference to angular-mocks.js in index.html) to enable mocking of the backend; unlike other approaches that use protractor.addMockModule() and ngMockE2E.

    Did anything further come of this issue? I'm striking a similar problem with $http.defaults being undefined. In my case, I'm setting a default Authorization header (an API key) so that I don't have to manually specify credentials in every $http request:

    
    // Set the Authorization header for all http requests
    $http.defaults.headers.common.Authorization = apiKey;
    

    If I run my protractor tests without protractor-http-mock (against the actual backend), everything is fine; but when I mock the backend, I get a TypeError: Cannot read property 'headers' of undefined error.

    I can probably work around this issue by modifying the app source to create defaults if it doesn't exist, e.g.

    
    // Set the Authorization header for all http requests
    $http.defaults = $http.defaults || {headers: {common: {}};
    $http.defaults.headers.common.Authorization = apiKey;
    

    But it would seem like something that this module should ideally handle by default (no pun intended).

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

    I completely agree with you . This shouldn't be a problem and I'll look into it as soon as I can. I never heard back from anybody else in the thread.

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

    Can you please fix this asap. I can confirm that the fix by azevedo-252 works.

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

    Sure thing.

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

    Done. It's part of version 0.1.8 that was just published.

    点赞 评论 复制链接分享

相关推荐