I am new in Angular testing and at the moment I am trying to test this piece of code but I'm getting an error concerning the event raised on the DOM:
<li class="list-group-item" *ngFor="let user of users">
<a class="test-link"[routerLink]="['/detail', user.id]">
{{user.userName}}
</a>
</li>
The Test file:
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [AdminComponent, UserDetailComponent],
imports: [HttpClientModule,RouterTestingModule.withRoutes([
{path:'detail/:id',
component: UserDetailComponent}],
)],
providers: [UserService, AuthService]
})
.compileComponents();
}));
beforeEach(() => {
router = TestBed.get(Router);
location = TestBed.get(Location);
fixture = TestBed.createComponent(AdminComponent);
debugElement = fixture.debugElement;
component = fixture.componentInstance;
fixture.detectChanges();
});
it('test demands redirection', fakeAsync(() => {
debugElement
.query(By.css('.test-link'))
.nativeElement.click();
tick();
expect(location.path()).toBe('/detail/testing/1');
}));
Why is click event on the native element is null?