Fix Angular 2 Tests with Karma

Below are some fixes I had to apply in order to make Angular 2 tests work with karma.


  • Error: Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’
  • Solution: Import FormsModulein your test:

Unknown component

  • Error: ‘custom-component’ is not a known element
  • Solution: Declare the component in your test:

Note: If the element is in another module, then import the other module (like in the previous case) instead of declaring elements one by one.

Unknown <router-outlet> tag

  • Error: ‘router-outlet’ is not a known element
  • Solution: Import RouterTestingModule:

Note: This list contains issues I’ve encountered. Please feel free to send me more.


A little experiment: If you find this post and ad below useful, please check the ad out :-)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to top