The components are as follows: App component:
@Component({
selector: 'app',
templateUrl: './app.component.html',
providers: [EmployeePictureService]
})
export class AppComponent {
pictures: string[];
@ViewChild('employee') employees: EmployeesComponent;
constructor(private employeePictureService : EmployeePictureService){
this.pictures = employeePictureService.getAllEmpPictures();
}
ngInit(){getPictures();}
employeesStillValid(){
const validity = this.employees.getEmployeeValidityMap();
let employeesValid= true;
if (validity) {
validity.forEach(function (value, key) {
if (value === false) {
employeesValid= false
}
});
return employeesValid;
}
}
}
app.component.html is as follows:
<div>
<employees #employee></employees>
<div>
<div [ngClass]="employeesStillValid()?'ok-active':'ok-inactive'"
(click)="Ok()">Ok</div>
</div>
Then the EmployeesComponent further has EmployeeDetailComponent.
export class EmployeeComponent {
@ViewChildren('employeeDetailComponent') employeeComponents:
EmployeeDetailComponent[];
employees: Employee[];
.......
}
Template of EmployeesComponent:
<div>
<div *ngFor="let employee of employees">
<employee-details [eachEmployeeObj]=employee
#employeeComponent></employee-details>
</div>
</div>
So there is a nesting of components happening here. employee-details is a
directive which includes specific details about each employee.
I would like to begin with using the NO_ERRORS_SCHEMA and write shallow
tests for the app component and test for the creation of the sub and
sub-sub component.
describe('AppComponent', () => {
let comp: AppComponent;
let fixture: ComponentFixture<AppComponent>;
let de: DebugElement;
let el: HTMLElement;
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [AppComponent],
providers: [
EmployeePictureService],
schemas: [NO_ERRORS_SCHEMA],
imports: [
BrowserModule, HttpModule
],
}).compileComponents().then(() => {
fixture = TestBed.createComponent(AppComponent);
comp = fixture.componentInstance;
fixture.autoDetectChanges();
});
});
it('should check comp instance exists', () => {
expect(comp).toBeTruthy();
});
});
The schema does not seem to be working for me as component is still
undefined in the test added.
Another error is - ERROR: 'Unhandled Promise rejection:'
this.employees.getEmployeeValidityMap is not a function
--
You received this message because you are subscribed to the Google Groups
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.