• Table of Contents
  • Introduction
  • Goal
  • Unit tests
  • Code coverage
  • Helpful resources
  • Run frontend tests
  • Coverage reports
  • Reading a coverage report
  • Ensuring that coverage is maintained
  • Write frontend tests
  • Unit test structure
  • describe
  • beforeEach
  • it
  • afterEach
  • afterAll
  • expect
  • tick
  • Note: This function will only work if the tests are running in the fakeAsync() block.
  • flush
  • Note: This function will only work if the tests are running in the fakeAsync() block.
  • Good practices
  • Tests should work in any order
  • Do not test private methods/properties
  • Worry about behavior and not about coverage
  • Name variables clearly
  • Name tests clearly
  • Check return values from the code being tested
  • Test the interface, not the implementation
  • Keep tests clean and clear
  • Similar tests should have similar checks
  • Validate external side-effects
  • General tips
  • Debugging
  • Spy utilities
  • Spying on third-party libraries
  • Spying on the same method/property more than one time in the same scope
  • Spies that change global values
  • Handling window events and reloads
  • When window calls reload
  • Using the same object reference in both file and spec file
  • Handling dates
  • Handling asynchronous code
  • Making HTTP calls
  • Setting up CsrfToken
  • HTTP calls in AngularJS
  • HTTP calls in Angular 2+
  • Using done and done.fail from Jasmine
  • Handling $timeout correctly
  • Mocking with $q API in AngularJS
  • When upgraded services should be imported in the test file
  • beforeEach calls in AngularJS
  • How to handle common errors
  • Testing services
  • Testing AngularJS services
  • Testing Angular 2+ services
  • Testing controllers
  • Testing directives and components
  • Testing AngularJS directives and components
  • Testing Angular2+ directives and components
  • Contacts