Skip to content

Latest commit

 

History

History
39 lines (23 loc) · 1.67 KB

README.md

File metadata and controls

39 lines (23 loc) · 1.67 KB

Angular Unit Testing Standards

Abstract

Unit testing can be describe as:

For every automatic action that occurs on controller initialization, or any controller method invoked in scope, test the following:

  1. Given correct input, does it call the expected external methods/query the expected external resources.
  2. Given correct results from all external methods/resources, does it generate the expected response.

If required by design:

  1. Given incorrect input, does it refuse the input with useful errors.
  2. Given incorrect results from external methods/resources, does it generate useful errors.

It should be immediately obvious what a test is testing, and why. If it isn't obvious, comments explaining/justifying the test assertions should be added.

When unit testing, we want to test at the smallest level possible.

Libraries

Docs Help Keywords
ngMock ngMock.md module, inject, $controller, $httpBackend
Sinon sinon.md stub, spy, called
Chai chai.md expect, to, equal, be
Sinon-chai N/A to.have.been.called (allows better chaining)
Mocha mocha.md describe, it, before, beforeEach, after, afterEach
Karma N/A Simply runs the tests

What do I test?

Unit Testing Chart

Credit to Sandi Metz from her talk at RailsConf 2013.