AngularJS
Unit Testing with Karma & Jasmine
AngularJS Unit Testing with Karma & Jasmine Getting started - - PowerPoint PPT Presentation
AngularJS Unit Testing with Karma & Jasmine Getting started with testing Angular AngularJS is built with testing in mind Testing is a good approach to reap the following benefits keep code maintainable, o Keep code understandable,
Unit Testing with Karma & Jasmine
benefits
fun, and help us sleep better at night
they appear in production
tablets or on a headless PhantomJS instance.
$ npm install --save-dev karma
$ npm install -g karma-cli
test framework and Google Chrome as target browser $ npm install jasmine-core karma-jasmine karma-chrome-launcher --save-dev
$ karma init karma.conf.js
// list of files / patterns to load in the browser files: [ 'node_modules/angular/angular.js', 'node_modules/angular-mocks/angular-mocks.js’, './*.js', 'tests/*Spec.js' ],
services into your unit tests $ npm install angular-mocks --save-dev
$ karma start karma.conf.js
with scripts section to run karma $ npm test
"scripts": { "test": "karma start karma.conf.js” },
the Jasmine framework as the basis for our tests.
http://jasmine.github.io/2.4/introduction.html describes the
Jasmine testing framework.
JavaScript code
describe Your Tests
it must do to perform the tests
tested.
the controller being tested.
beforeEach block
using the it function.
controller tests for sample application.
angularjs-testing/