How do you mock a component in Angular 2.0.0 Final Release? I have a problem in mocking a component that has a variable that I use for logic in another component. Specifically, I want to mock a PrimeNG Datatable selection.
Sample code below.
table.component.html
<p-dataTable
#table
[value]="myDatasource"
[(selection)]="mySelections"
...
>
table.component.ts
@Component({
selector: 'my-table',
templateUrl: './table.component.html'
})
export class TableComponent{
@ViewChild('table') datatable;
my-component.component.html
<my-table #mytable></my-table>
my-component.component.ts
@Component({
selector: 'my-component',
templateUrl: './my-component.component.html'
})
export class MyComponent {
@ViewChild('#mytable') mytable;
myFunction() : void {
if(this.mytable.table.selection.length === 0){
console.log();
} else{
console.log();
}
}
How do I mock it so that I can set values to the selection in the table.component.ts to test in the my-component.component.ts?