Testing harness for Angular scopes, controllers, and providers. Streamlines the boilerplate created by needing to inject dependencies for Angular Unit Testing. Abstracts other features, and wraps setup and cleanup operations in easy to use functions.
npm Install
npm install ngtestharness
Modules Loaded By Default
- ng
- ngMock
- ngSanitize
Additional modules, should be included in the modules parameter.
Note: Loading ngCookies
adds new functionality to the testing harness. (Please see handleCookie
and clearCookies
in the API)
API
If using Jasmine
-
Make sure your SpecRunner includes:
- Angular
- Angular Mocks
- Angular Sanitize
-
The files should include at least the three angular files above, the harness filepath, the paths to all spec and source files, and the path to your modularized template files.
- The easiest way to get this is to run your templates through the grunt-html2js and use the created file. You could easily put this whole process into grunt using grunt-contrib-jasmine.
- Open the SpecRunner in a browser.
Jasmine Modularized Templates Example
angular; angular;
Jasmine SpecRunner Test Example
;
If using Karma
-
Make sure the Karma configuration includes:
- Angular
- Angular Mocks
- Angular Sanitize
-
The files should include at least the three angular files above, the harness filepath, the paths to all spec and source files, and all template files.
-
Install the karma-ng-html2js-preprocessor, preferably through npm
-
Add the 'karma-ng-html2js-preprocessor' plugin to your karma configuration file.
-
Add a filepath pattern that will include your html templates in the preprocessors section.
-
Run Karma
plugins: 'karma-ng-html2js-preprocessor'
preprocessors: "'*.html': 'ng-html2js'"
Karma Test Example (Using Jasmine)
;
Authors
Contributors
License
Articles
- ngTestHarness: Strap in with this new testing helper for Angular
- Using ngTestHarness to simplify $httpBackend testing
Copyright (c) 2014-2015 Gaikai Inc. (A Sony Computer Entertainment Company). Visit us at https://gaikai.com/ for more information.