Unit testing ionic apps


#1

Any examples of writing unit tests for an ionic app using jasmine, karma ?

How to inject ionic module, testing states etc…

write now iam stuck at-

beforeEach(function(){
module(‘app’);
module(‘ionic’);
});

Error: [$injector:modulerr] Failed to instantiate module app due to:
Error: [$injector:modulerr] Failed to instantiate module ionic due to:
Error: [$injector:nomod] Module 'ionic' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

#2

any suggestions on how to load ionic module for unit test. Iam able to load a mock module. is that the best practice or loading the actual ionic module?


#3

For me reorganizing the karma.conf file solved the problem.
Change order of including your scripts, files and libraries:

// libraries
'www/lib/ionic/js/ionic.bundle.min.js',
'www/lib/angular-ui-router/release/angular-ui-router.min.js',
'www/lib/angular-mocks/angular-mocks.js',
'www/lib/angular-route/angular-route.js',
'www/lib/angular-translate/angular-translate.js',

// scripts
'app/js/config.js',
'app/js/app.js',
'app/js/i18n/*.js',
'app/js/controller/*.js',

// specs
'test/unit/controller/*.js'
[...]

#4

I am new to ionic and will be starting a project using Ionic. Are there any helpful link for Unit Testing ionic apps?


#5

Do we really need ‘www/lib/angular-route/angular-route.js’, when we are using angular-ui-router.