Unit testing 使用withCredentials标志的单元测试

Unit testing 使用withCredentials标志的单元测试,unit-testing,angular,Unit Testing,Angular,我们正在构建一个使用withCredentials标志的应用程序。参考问题,我们可以使用withCredentials标志。现在,我正尝试使用mockbackend对服务进行单元测试。只要我删除withCredentials标志,我就可以让一切正常工作 我的服务: @Injectable() export class AccountService { public productParams; constructor( private http: Http) { //

我们正在构建一个使用withCredentials标志的应用程序。参考问题,我们可以使用withCredentials标志。现在,我正尝试使用mockbackend对服务进行单元测试。只要我删除withCredentials标志,我就可以让一切正常工作

我的服务:

@Injectable()
export class AccountService {
  public productParams;

  constructor(
    private http: Http) {
    // This allows the cookie to be set and sent.
    // It appears that once the cookie is set with login, it works for each call (even in other services)
     let _build = (<any>http)._backend._browserXHR.build;
     (<any>http)._backend._browserXHR.build = () => {
       let _xhr = _build();
       _xhr.withCredentials = true;
       return _xhr;
     };
  }
}
我猜问题是因为withCredentials标志在我的mockbackend中没有被模拟。那我该怎么做呢?或者我可以用另一种方式设置我的
http
withCredentials标志吗

错误:

     6) should return mocked response
         AccountService
         _instantiateProvider@C:/sites/Scratch/prototype_ui/config/karma-test-shim.js:18071:38 <- webpack:///~/@angular/core/src/di/reflective_injector.js:626:0
    _new@C:/sites/Scratch/prototype_ui/config/karma-test-shim.js:18060:42 <- webpack:///~/@angular/core/src/di/reflective_injector.js:615:0
    getObjByKeyId@C:/sites/Scratch/prototype_ui/config/karma-test-shim.js:17715:55 <- webpack:///~/@angular/core/src/di/reflective_injector.js:270:0
    _getByKeyDefault@C:/sites/Scratch/prototype_ui/config/karma-test-shim.js:18240:52 <- webpack:///~/@angular/core/src/di/reflective_injector.js:795:0
    _getByKey@C:/sites/Scratch/prototype_ui/config/karma-test-shim.js:18212:42 <- webpack:///~/@angular/core/src/di/reflective_injector.js:767:0
    get@C:/sites/Scratch/prototype_ui/config/karma-test-shim.js:18021:31 <- webpack:///~/@angular/core/src/di/reflective_injector.js:576:0
    C:/sites/Scratch/prototype_ui/config/karma-test-shim.js:26166:75 <- webpack:///~/@angular/core/testing/test_injector.js:46:46
    map@[native code]
    execute@C:/sites/Scratch/prototype_ui/config/karma-test-shim.js:26166:33 <- webpack:///~/@angular/core/testing/test_injector.js:46:0
    C:/sites/Scratch/prototype_ui/config/karma-test-shim.js:26255:63 <- webpack:///~/@angular/core/testing/test_injector.js:135:28
    C:/sites/Scratch/prototype_ui/config/karma-test-shim.js:26480:29 <- webpack:///~/@angular/core/testing/testing.js:98:0 _instantiate@C:/sites/Scratch/prototype_ui/config/karma-test-shim.js:18197:98 <- webpack:///~/@angular/core/src/di/reflective_injector.js:752:0
    14 06 2016 02:36:45.593:WARN [reporter]: SourceMap position not found for trace: TypeError: undefined is not an object (evaluating 'service.getUsers') in http://localhost:9867/base/config/karma-test-shim.js?e346472b463b1f48b98add9734c44e8d5946fda0 (line 44942)
    http://localhost:9867/base/config/karma-test-shim.js?e346472b463b1f48b98add9734c44e8d5946fda0:44942:17
    http://localhost:9867/base/config/karma-test-shim.js?e346472b463b1f48b98add9734c44e8d5946fda0:26480:29
     TypeError: undefined is not an object (evaluating 'service.getUsers') in C:/sites/Scratch/prototype_ui/config/karma-test-shim.js (line 44942)
C:/sites/Scratch/prototype_ui/config/karma-test-shim.js:44942:17 <- webpack:///spec/services/account.service.spec.ts:26:0
C:/sites/Scratch/prototype_ui/config/karma-test-shim.js:26480:29 <- webpack:///~/@angular/core/testing/testing.js:98:0
6)应返回模拟响应
会计服务

_instantiateProvider@C:/sites/Scratch/prototype_ui/config/karma test shim.js:18071:38这是完整的错误消息吗?谢谢@那不是我的错。我会提供完整的(和巨大的)一个。这是完整的错误信息吗?谢谢@那不是我的错。我会提供完整的(和巨大的)一个。
     6) should return mocked response
         AccountService
         _instantiateProvider@C:/sites/Scratch/prototype_ui/config/karma-test-shim.js:18071:38 <- webpack:///~/@angular/core/src/di/reflective_injector.js:626:0
    _new@C:/sites/Scratch/prototype_ui/config/karma-test-shim.js:18060:42 <- webpack:///~/@angular/core/src/di/reflective_injector.js:615:0
    getObjByKeyId@C:/sites/Scratch/prototype_ui/config/karma-test-shim.js:17715:55 <- webpack:///~/@angular/core/src/di/reflective_injector.js:270:0
    _getByKeyDefault@C:/sites/Scratch/prototype_ui/config/karma-test-shim.js:18240:52 <- webpack:///~/@angular/core/src/di/reflective_injector.js:795:0
    _getByKey@C:/sites/Scratch/prototype_ui/config/karma-test-shim.js:18212:42 <- webpack:///~/@angular/core/src/di/reflective_injector.js:767:0
    get@C:/sites/Scratch/prototype_ui/config/karma-test-shim.js:18021:31 <- webpack:///~/@angular/core/src/di/reflective_injector.js:576:0
    C:/sites/Scratch/prototype_ui/config/karma-test-shim.js:26166:75 <- webpack:///~/@angular/core/testing/test_injector.js:46:46
    map@[native code]
    execute@C:/sites/Scratch/prototype_ui/config/karma-test-shim.js:26166:33 <- webpack:///~/@angular/core/testing/test_injector.js:46:0
    C:/sites/Scratch/prototype_ui/config/karma-test-shim.js:26255:63 <- webpack:///~/@angular/core/testing/test_injector.js:135:28
    C:/sites/Scratch/prototype_ui/config/karma-test-shim.js:26480:29 <- webpack:///~/@angular/core/testing/testing.js:98:0 _instantiate@C:/sites/Scratch/prototype_ui/config/karma-test-shim.js:18197:98 <- webpack:///~/@angular/core/src/di/reflective_injector.js:752:0
    14 06 2016 02:36:45.593:WARN [reporter]: SourceMap position not found for trace: TypeError: undefined is not an object (evaluating 'service.getUsers') in http://localhost:9867/base/config/karma-test-shim.js?e346472b463b1f48b98add9734c44e8d5946fda0 (line 44942)
    http://localhost:9867/base/config/karma-test-shim.js?e346472b463b1f48b98add9734c44e8d5946fda0:44942:17
    http://localhost:9867/base/config/karma-test-shim.js?e346472b463b1f48b98add9734c44e8d5946fda0:26480:29
     TypeError: undefined is not an object (evaluating 'service.getUsers') in C:/sites/Scratch/prototype_ui/config/karma-test-shim.js (line 44942)
C:/sites/Scratch/prototype_ui/config/karma-test-shim.js:44942:17 <- webpack:///spec/services/account.service.spec.ts:26:0
C:/sites/Scratch/prototype_ui/config/karma-test-shim.js:26480:29 <- webpack:///~/@angular/core/testing/testing.js:98:0