我无法读取未定义的属性“

时间:2018-07-24 21:16:56

标签: angular karma-jasmine routerlink

我认为我在编写测试时缺少一些基础知识,因为我的测试都没有通过。我正在使用Angular,然后使用Jasmine进行单元测试。我目前正在尝试测试routerLink。这是我所拥有的:

beforeEach(async(() => {
  TestBed.configureTestingModule({
    declarations: [ HeaderComponent ],
    schemas: [ NO_ERRORS_SCHEMA ],
    imports: [RouterTestingModule.withRoutes([])]
  })
  .compileComponents();
}));

beforeEach(() => {
    fixture = TestBed.createComponent(HeaderComponent);
    component = fixture.componentInstance;
    fixture.detectChanges();
});

it('should have a link to login page', () => {
  let de = fixture.debugElement.queryAll(By.directive(RouterLinkWithHref));
  let index = de.findIndex(de => de.properties['href'] === '/login');
   expect(index).toBeGreaterThan(-1);
 });


 it('should have a link to dashboard page', () => {
  let deB = fixture.debugElement.queryAll(By.directive(RouterLinkWithHref));
  let index = deB.findIndex(de => de.properties['href'] === '**');
   expect(index).toBeGreaterThan(-1);
 });

这是我得到的错误:

TypeError: Cannot read property 'debugElement' of undefined as well as 
Error: Template parse errors:
There is no directive with "exportAs" set to "matMenu" (aderComponent.html@22:14
There is no directive with "exportAs" set to "matMenu"

0 个答案:

没有答案