I'm trying to do angular2 tests and running into problems. I am trying to test a binding in the HTML and getting error "ReferenceError: google is not defined" when testing angular 2 component. How can I get id of element?
my-component.html
<ul class="nav nav-list">
<a *ngFor="let plan of plansNames" style="color:grey;"class="list-group-item" [routerLink]="['/annotations']" [queryParams]="{ id: plan.id }" >
<i class="material-icons" id=>layers</i>
</a>
</ul>
my component.spec.ts
import { HttpModule } from '@angular/http';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DebugElement } from '@angular/core';
import { PlansComponent } from './plans.component';
import { Location, CommonModule } from '@angular/common';
import { RouterTestingModule } from '@angular/router/testing';
import {async, fakeAsync, tick} from '@angular/core/testing';
import {DefaultApi} from "../api/api/DefaultApi";
import {TableData } from './table-data';
import { Router, NavigationEnd } from '@angular/router';
import { RouterLinkWithHref } from '@angular/router';
describe('DOM Elements testing', () => {
let comp : PlansComponent;
let fixture : ComponentFixture<PlansComponent>;
let de : DebugElement;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
PlansComponent
],
imports: [RouterTestingModule,HttpModule]
}).compileComponents();
}));
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
PlansComponent
]
});
TestBed.compileComponents();
fixture = TestBed.createComponent(PlansComponent);
fixture.detectChanges();
de = fixture.debugElement;
});
it('Plan was created',() => {
fixture.detectChanges();
expect(de.nativeElement.querySelector('a[ng-reflect-router-link= "/annotations"]').getAttribute('ng-reflect-href')).toMatch('/annotations')
});
it('Plan has class list-group-item',() => {
expect(de.nativeElement.querySelector('ul.nav-list a').getAttribute('class')).toMatch('list-group-item')
});
Can it be because function ngOnInit is not called yet,and DOM elements are not created?
Aucun commentaire:
Enregistrer un commentaire