ionic start ionic-testing tabs cd ionic-testing
npm install karma karma-jasmine karma-phantomjs-launcher --save-dev npm install -g karma-cli npm install bower install angular-mocks --save-dev
mkdir tests cd tests karma init my.conf.js
// list of files / patterns to load in the browser files: [ '../www/lib/angular/angular.js', '../www/js/*.js', '../www/lib/angular-mocks/angular-mocks.js', '**/*tests.js' ], // Use the PhantomJS browser instead of Chrome browsers: ['PhantomJS'],
// var KarmaServer = require('karma').Server; // ... gulp- // gulp-task gulp.task('test', function(done) { new KarmaServer({ configFile: __dirname + '/tests/my.conf.js', singleRun: true, }, done).start(); });
describe('Controllers', function(){ var scope; // load the controller's module beforeEach(module('starter.controllers')); beforeEach(inject(function($rootScope, $controller) { scope = $rootScope.$new(); $controller('AccountCtrl', {$scope: scope}); })); // tests start here it('should have enabled friends to be true', function(){ expect(scope.settings.enableFriends).toEqual(true); }); });
gulp task
describe('Chats Unit Tests', function() { var Chats; beforeEach(module('starter.services')); beforeEach(inject(function(_Chats_) { Chats = _Chats_; })); it('can get an instance of my factory', inject(function(Chats) { expect(Chats).toBeDefined(); })); it('has 5 charts', inject(function(Chats) { expect(Chats.all().length).toEqual(5); })); it('has Max as friend with id 1', inject(function(Chats) { var oneFriend = { id: 1, name: "Max Lynx", notes: 'Odd obsession with everything', face: '' }; expect(Chats.get(1).name).toEqual(oneFriend.name); })) })
gulp test
.Source: https://habr.com/ru/post/270485/
All Articles