我正在测试一个包含routerlink的功能,它的参数可以导航到详细页面
这是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'.
我有点迷茫,因为我是集成测试的新手,而且对于我搜索的内容,没有任何帮助,所以我在这里缺少一些逻辑,有人可以指出解决方案吗?