Are there any documentations somewhere for writing unit tests for ionic framework ?
I didn’t find such documentations and simply created angularjs unit test under test/unit folder in root folder, however when I run npm test on this folder nothing happens.
I tried to move test folder under www, but then running npm test in www folder fails since package.json file doesn’t exist in this folder.
All our components get tested before we make commits or when make a new component. As far as unit tests go, there are some articles out there that are for angular
http://andyshora.com/unit-testing-best-practices-angularjs.html
But this a good idea for the devs to write about how to write some tests for ionic apps. I’ll get in touch with them and let them know.
Thanks.
Any idea why running “npm test” doesn’t produce any output ? Is it because it didn’t find any tests to execute ?
Any update on this. We are starting a project in Ionic and hence very much interested to know how to do unit testing our work
Yes. I was finally able to execute unit tests using karma.
It took me a while to configure it properly though.
I defined a test folder, inside this folder I defined conf.js project with the following definitions:
frameworks: ['jasmine'],
files: [
'../www/lib/ionic/js/angular/angular.js',
'../www/lib/ionic/js/angular/angular-animate.js',
'../www/lib/ionic/js/angular/angular-resource.js',
'../www/lib/ionic/js/angular/angular-sanitize.js',
'../www/lib/ionic/js/angular/angular-mock.js',
'../www/lib/ionic/js/angular-ui/angular-ui-router.js',
'../www/js/bootstrap-custom/ui-bootstrap-custom-0.10.0.js',
'../www/lib/ionic/js/ionic.js',
'../www/lib/ionic/js/ionic-angular.js',
'../www/js/*.js',
'myFirstSpec.js',
'mySecondSpec.js',
'myThirdSpec.js'
],
plugins: [
'karma-chrome-launcher',
'karma-jasmine'
],
Your list of files may look a bit different, depend what are you dependencies.
Notice you need to install also the 2 plugins defined above.
Look for some tutorials, such as this one:
http://www.tuesdaydeveloper.com/2013/06/angularjs-testing-with-karma-and-jasmine/
for more info.
I also had to install karma-cli plugin to use command line menu like init, start etc.
This thing was never communicated to core devs?
@mhartington Is there any reason why angular-mocks isn’t included in Ionic 1.0.0? It can be pulled in using bower, but hopefully everyone is writing unit tests for their applications so it seems odd not to included it.