title: Angular 2.0.0 - Mocking Components
body: <p>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 <strong>PrimeNG Datatable</strong> selection.</p>
  
  <p>Sample code below.</p>
  
  <p><strong>table.component.html</strong></p>
  
  <pre><code>        &lt;p-dataTable
            #table
            [value]="myDatasource"
            [(selection)]="mySelections"
            ...
          &gt;
  </code></pre>
  
  <p><strong>table.component.ts</strong></p>
  
  <pre><code>@Component({
    selector: 'my-table',
    templateUrl: './table.component.html'
  })
  
  export class TableComponent{
      @ViewChild('table') datatable;
  </code></pre>
  
  <p><strong>my-component.component.html</strong></p>
  
  <pre><code>&lt;my-table #mytable&gt;&lt;/my-table&gt;
  </code></pre>
  
  <p><strong>my-component.component.ts</strong></p>
  
  <pre><code>@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();
      }
    }
  </code></pre>
  
  <p>How do I mock it so that I can set values to  the <strong><em>selection</em></strong> in the <strong>table.component.ts</strong> to test in the <strong>my-component.component.ts</strong>?</p>