title: Unit-testing with Jasmine/Karma on an Angular Google Charts component
body: <p>I haven't found any way of doing an unit-test with Jasmine/Karma on an Angular2component which renders a chart from Google Charts. So I propose my own Q&amp;A in the hope that it could help other people also testing it:</p>
  
  <p><em>What could be a good way to write a reliable test for a component like the one on the example below, that has a function to update the chart view when window is resized?</em></p>
  
  <pre><code>import { Component, OnInit, Input } from '@angular/core';
  import { Router } from '@angular/router';
  
  declare var google: any;
  
  @Component({
    selector: 'app-chart',
    templateUrl: './chart.component.html',
    styleUrls: ['./chart.component.scss'],
  })
  export class ChartComponent implements OnInit {
    @Input()
    chartData: string[][];
  
    options: {} = {
      height: 320,
    };
  
    constructor(private router: Router) {}
  
    ngOnInit() {
      google.charts.load('current', { packages: ['corechart'] });
      google.charts.setOnLoadCallback(() =&gt; this.drawChart(this.chartData));
      window.addEventListener('resize', () =&gt; {
        if (this.router.url === '/chart') {
          return this.drawChart(this.chartData);
        }
      });
    }
  
    drawChart(chartData) {
      const data = google.visualization.arrayToDataTable(chartData);
      const chart = new google.visualization.LineChart(
        document.querySelector('#chart'),
      );
      chart.draw(data, this.options);
    }
  }
  </code></pre>