[Fixed] Angular 2 Unit testing with 3rd party components


I’m trying to write a unit test for my component which has a PrimeNG piechart directive in it. PrimeNG uses Chart.js which is included in my index.html and I’ve added it to my files list in the test config. When I execute my test it says Can't find variable: Chart. If I remove the 3rd party component from my template the test passes. What is the proper way to create a unit test with a 3rd party component?


In addition to include your files, I think that you also need to configure them into the SystemJS configuration:

  • If you execute your test from an HTML page, define this directly in System.config in this page.
  • If you execute your test using Karma, extend System.config in the karma-test-shim.js file.

Leave a Reply

(*) Required, Your email will not be published