Cześć.
Testuje swój kod i mam dwa problemy:
kod , który testuje:
@ViewChild('myTasksComponentRef') myTasksComponentRef: MyTasksComponent;
@ViewChild('addTaskComponentRef') addTaskComponentRef: AddTaskComponent;
constructor() { }
ngAfterViewInit(): void {
this.showAll();
}
showAll() {
this.myTasksComponentRef.getVal(null);
}
newTask() {
this.addTaskComponentRef.closerManager(true);
}
Test tego kodu:
describe('ProjectComponent', () => {
let component: ProjectComponent;
let fixture: ComponentFixture<ProjectComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
ProjectComponent,
]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(ProjectComponent);
component = fixture.componentInstance;
});
it('should create', () => {
expect(component).toBeTruthy(); // doc here we check a successful create a object of component
});
it('should test button correctly design', () => {
const button = fixture.debugElement.query(By.css('button')).nativeElement;
expect(button).toBeTruthy();
expect(button.textContent).toContain('Nowy projekt');
});
it('should test button correctly works', () => {
// const form = fixture.debugElement.query(By.css('form')).nativeElement;
const button = fixture.debugElement.query(By.css('button')).nativeElement;
button.click(true);
//fixture.detectChanges(); tutaj jest perwszy błąd
//expect(form.textContent).toBeTruthy();
});
});
1) błąd jak od komentuje w teście fixture.detectChanges() to dostaje błąd ,że myTasksComponentRef nie jest funkcją :
ProjectComponent should test button correctly works FAILED
TypeError: this.myTasksComponentRef.getVal is not a function
2) to chciałem zrobić aby przetestować czy po kliknięciu buttona otwiera się nowa karta posiadająca form ,ale za chiny ciągle wywala mi ,że nie może pobrać takiej wartości z nieistniejącego elementu.
Z góry bardzo dziękuje za pomoc i wszelkie uwagi.