Introduction to Testing in AngularJS

Handsontable JavaScript Spreadsheet Most popular component for web apps
This article is based on Misko Herveys presentation on testing in Angular.

  1. Learn to read code
  2. Mind your dependencies
  3. Setting up your environment
“Writing the test is easier than running the application.”
“It’s quicker than manually testing.”
“Writing more code (for defining tests) does NOT mean it takes longer than testing manually.”
It might be nearly 1:1 in amount of code but it’s fundamentally different in code structure. Application code can contain deep listing of loops etc while tests code is flat, essentially a sequential a series of describe, if, assert statements etc…

“It’s hard to write tests and IT IS a skillset.”
Global state is hard to test as it’s hard to control.
“The difficulty of writing a test is to do with the structure of the code and what parts of it you can control through “mocking” functionality.”

Can Protractor and Karma be used together?

Protractor and Karma should not be used together; instead they provide separate systems for running tests. Protractor and Karma cover different aspects of testing – Karma is intended mostly for unit tests, while Protractor should be used for end to end testing.

Protractor is built on top of WebDriverJS, which uses a Selenium/WebDriver server to provision browsers and drive test execution. Examples of pure WebDriverJS can be found here:

Georgios – I think it makes sense to keep Protractor and Karma separate – for end to end tests, you want the native event driving and flexibility of webdriver, while for unit tests you want fast execution and autowatching of files.


Sam Deering

Sam Deering

Sam is a web developer, online entrepreneur and investor. In his spare time he enjoys coding, playing chess and sharing what he learns with others.

One thought on “Introduction to Testing in AngularJS

Leave a Reply

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