Testing AngularJS

Angular Unit Tests

See John Papa's AngularJS Testing Examples. You can download the
codebase and try out tests. If you want to start a new codebase that utilizes this testing strategy, you can use
Angular Hot Towel to scaffold a new project for you. Keep in mind that
you probably not need the src/server folder nor the separate src/client folder in the generated codebase

In the src/client/app folder in the example codebase, you will find several component folders.

In those component folders, you will find spec.js files for tests of controllers, route definitions, and services.

For examples from an ES2015 code base, refer to the NG6 codebase.

In the client/app/components/ folders, you will find examples of tests.

Resources

Refer to the Angular Style Guide for general
information on testing in Angular.

There is also a Pluralsight Course on Angular Testing.

Libraries

  • Mocha for unit tests
  • Chai for assertions.
  • Sinon for spies, stubs, and mocks.
  • PhantomJS provides the web stack for testing.
  • Karma is the test runner.