Я тестирую функцию, включающую роутерлинк и его параметры для перехода на подробную страницу
Это HTML
<li class="list-group-item" *ngFor="let user of users">
<a class="test-link"[routerLink]="['/detail', user.id]">
{{user.id}}
</a>
</li>
Файл спецификации:
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;
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('test demands redirection', fakeAsync(() => {
component.users = [{
id: '',
userName: '',
password: '',
firstName: '',
lastName: ''
}
];
fixture.detectChanges();
debugElement
.query(By.css('.test-link'))
.nativeElement.click();
expect(location.path()).toBe('/detail/1');
Ошибка указывает на последнюю строку, поскольку она игнорировала аргумент location.path()
: Expected '' to be '/detail/1'.
Я немного растерялся, так как я новичок в интеграционных тестах и что касается того, что я искал, ничегоработает, так что мне не хватает логики здесь, кто-то может указать мне решение?