【问题标题】:Testing angular project service for specific headers in $http requests using $httpBackend, jasmine使用 $httpBackend, jasmine 测试 $http 请求中特定标头的 Angular 项目服务
【发布时间】:2014-11-19 10:24:43
【问题描述】:

我想检查请求中是否存在特定标头。这是帮助我找到标题的文章。

http://jbavari.github.io/blog/2014/06/20/testing-interceptor-headers-in-angularjs/

以下是我测试的sn-p。这使我可以访问标头,但问题是(将是),当我刷新请求时,它期望标头作为一个函数,这隐含地使我的测试失败。

$httpBackend
    .expect('POST', 'https://www.someurl.com/login',
      userObj, function (headers) {
        expect(headers['content-type']).toBe('application/x-www-form-urlencoded');
      })
    .respond();

有什么建议吗?

【问题讨论】:

    标签: javascript angularjs


    【解决方案1】:

    几个链接帮助了我。

    Testing AngularJs' $http.defaults.headers.common if specific header is set

    http://andrewfong.com/blog/2014/09/22/angularjs-testing-headers-with-whenget-expectget/

    $httpBackend
        .expect('POST', 'https://www.someurl.com/login',
          userObj, function (headers) {
            expect(headers['content-type']).toBe('application/x-www-form-urlencoded');
    
            // MUST return boolean
            return headers['content-type'] ===  'application/x-www-form-urlencoded';
          })
        .respond();

    【讨论】:

      猜你喜欢
      • 2023-04-02
      • 1970-01-01
      • 2021-12-19
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 2018-12-20
      • 2016-06-03
      • 2020-02-14
      相关资源
      最近更新 更多