Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角向注入服务组件的Karma/Jasmine单元测试_Angular_Unit Testing_Karma Jasmine_Adal - Fatal编程技术网

Angular 角向注入服务组件的Karma/Jasmine单元测试

Angular 角向注入服务组件的Karma/Jasmine单元测试,angular,unit-testing,karma-jasmine,adal,Angular,Unit Testing,Karma Jasmine,Adal,我不熟悉Karma/Jasmine单元测试,我正在尝试为我的身份验证组件编写一些测试,该组件中注入了AuthService。我还将另一个用于Microsoft(Azure)身份验证的身份验证服务注入到通用身份验证服务中。为了构建我的规范,我有: describe('AuthAdminComponent', function () { let de: DebugElement; let comp: AuthAdminComponent; let fixture: ComponentFi

我不熟悉Karma/Jasmine单元测试,我正在尝试为我的身份验证组件编写一些测试,该组件中注入了AuthService。我还将另一个用于Microsoft(Azure)身份验证的身份验证服务注入到通用身份验证服务中。为了构建我的规范,我有:

describe('AuthAdminComponent', function () {
  let de: DebugElement;
  let comp: AuthAdminComponent;
  let fixture: ComponentFixture<AuthAdminComponent>;
  let authService: AuthService;

  let authServiceStub: {
    // Fill in later
  }

    beforeEach(async(() => {
    TestBed.configureTestingModule({
      declarations: [ AuthAdminComponent ], // declare the test component
      providers: [
        {provide: AuthService, useValue: authServiceStub},
      ]
    })
    .compileComponents(); // compile template and css
  }));

  beforeEach(() => {
    fixture = TestBed.createComponent(AuthAdminComponent);
    comp = fixture.componentInstance;
    authService = TestBed.get(authService) // Get the needed service
  });

})
我不太明白我哪里出错了。显然,它找不到该.js文件,但该.js文件确实存在于该位置,并且在我正常运行Angular应用程序时工作正常。所以我只是假设我设置的测试不正确?任何帮助都将不胜感激。我一直在尝试遵循有关测试的角度文档。如果这有帮助,下面是我的AuthService的开头:

import {Injectable} from '@angular/core';
import { Headers, Http, Response } from '@angular/http';
import 'rxjs/Rx';
import { Observable } from 'rxjs/Observable';
import { AdalService } from 'ng2-adal/core';

@Injectable()
export class AuthService {

    public authType: string = null;
    public connection: string = null;
    public accessToken: string = null;
    public refreshToken: string = null;

    constructor(private adalService: AdalService, private http: Http) {}

通过编辑karma.conf.js文件并向文件中添加:[]

{ pattern: 'node_modules/ng2-adal/**/*.js', included: false, watched: false },
{ pattern: 'node_modules/ng2-adal/**/*.js.map', included: false, watched: false },
{ pattern: 'node_modules/adal-angular/**/*.js', included: false, watched: false },
{ pattern: 'node_modules/adal-angular/**/*.js.map', included: false, watched: false },
{ pattern: 'node_modules/ng2-adal/**/*.js', included: false, watched: false },
{ pattern: 'node_modules/ng2-adal/**/*.js.map', included: false, watched: false },
{ pattern: 'node_modules/adal-angular/**/*.js', included: false, watched: false },
{ pattern: 'node_modules/adal-angular/**/*.js.map', included: false, watched: false },