For some Reason this line is failing, but within my logs it shows that the component was initialized with the correct value.
for (let i = 0; i < 20; i++) {
this['answer_' + (i + 1)] = new FormControl(this.questions[i].answer);
My Jasmine test spec:
it('should be created', () => {
let pvqStepUpService: PVQStepUpService = TestBed.get(PVQStepUpService);
pvqStepUpService.data = pvqstepUpResponse;
let questions = [];
questions = pvqStepUpService.data.pvqs;
let questionsArr = [];
let answerControlArr = [];
component.ngOnInit();
component.answerControlArr = answerControlArr;
component.questions = questions;
console.log('TEST COMPONENT ANSWER CONTROL ARR IS ---> ', component.answerControlArr[0]);
console.log('Test Component: ANSWER ARRAY ---> ', component.questions[0]);
console.log('TEST component FORMGROUP ---> ', component.pvqForm);
console.log("TEST ANSWER CONTROL ---> {}", component.answer_1);
console.log("TEST ANSWER OF QUESTION ---> ", component.questions[0].answer);
expect(component).toBeTruthy();
});
I solved it:
Had fixture.detectChanges(); outside of the it block, I placed it just before ngOninit after all my variables were initialized, and it worked.