Я пытаюсь проверить свой компонент с окончанием angular 2, но я получаю сообщение об ошибке, потому что компонент использует директиву routerLink
. Я получаю следующую ошибку:
Невозможно связать с 'routerLink', так как это не известное свойство 'a'.
Это соответствующий код шаблона ListComponent
<a
*ngFor="let item of data.list"
class="box"
routerLink="/settings/{{collectionName}}/edit/{{item._id}}">
И вот мой тест.
import { TestBed } from '@angular/core/testing';
import { ListComponent } from './list.component';
import { defaultData, collectionName } from '../../config';
import { initialState } from '../../reducers/reducer';
const data = {
sort: initialState.sort,
list: [defaultData, defaultData],
};
describe(`${collectionName} ListComponent`, () => {
let fixture;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
ListComponent,
],
}).compileComponents(); // compile template and css;
fixture = TestBed.createComponent(ListComponent);
fixture.componentInstance.data = data;
fixture.detectChanges();
});
it('should render 2 items in list', () => {
const el = fixture.debugElement.nativeElement;
expect(el.querySelectorAll('.box').length).toBe(3);
});
});
Я просмотрел несколько ответов на подобные вопросы, но не смог найти решение, которое сработало для меня.