Unit test configuration


#1

Hi,
I am new in unit testing and ionic.
I only found this blog that explains how to set configuration tests for the Ionic 2. And it works.
Now I added cordova plugin and ionic-native package. It works too ) But I can’t configure karma to the ionic-native package. Please, help me.

Log:

[17:08:03] Finished 'test' after 781 ms
28 02 2016 17:08:03.658:INFO [karma]: Karma v0.13.21 server started at http://localhost:9876/
28 02 2016 17:08:03.665:INFO [launcher]: Starting browser PhantomJS
28 02 2016 17:08:04.209:INFO [PhantomJS 2.1.1 (Mac OS X 0.0.0)]: Connected on socket /#7SCksZv7WXR_FVT2AAAA with id 71953561
PhantomJS 2.1.1 (Mac OS X 0.0.0) WARN: 'DEPRECATION WARNING: 'enqueueTask' is no longer supported and will be removed in next major release. Use addTask/addRepeatingTask/addMicroTask'
28 02 2016 17:08:05.454:WARN [web-server]: 404: /base/ionic-native.js
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR: 'http://localhost:9876/base/node_modules/systemjs/dist/system.src.js?281591da6090abed69cd0b080aa69c8de089a41c:733:14
run@http://localhost:9876/base/node_modules/zone.js/dist/zone-microtask.js?87bbeaae4d01ebf513e1bbea41a0e13dbad92eb4:1217:29
zoneBoundFn@http://localhost:9876/base/node_modules/zone.js/dist/zone-microtask.js?87bbeaae4d01ebf513e1bbea41a0e13dbad92eb4:1194:29
lib$es6$promise$$internal$$tryCatch@http://localhost:9876/base/node_modules/zone.js/dist/zone-microtask.js?87bbeaae4d01ebf513e1bbea41a0e13dbad92eb4:442:25
lib$es6$promise$$internal$$invokeCallback@http://localhost:9876/base/node_modules/zone.js/dist/zone-microtask.js?87bbeaae4d01ebf513e1bbea41a0e13dbad92eb4:454:53
lib$es6$promise$$internal$$publish@http://localhost:9876/base/node_modules/zone.js/dist/zone-microtask.js?87bbeaae4d01ebf513e1bbea41a0e13dbad92eb4:425:53
lib$es6$promise$$internal$$publishRejection@http://localhost:9876/base/node_modules/zone.js/dist/zone-microtask.js?87bbeaae4d01ebf513e1bbea41a0e13dbad92eb4:375:42
http://localhost:9876/base/node_modules/zone.js/dist/zone-microtask.js?87bbeaae4d01ebf513e1bbea41a0e13dbad92eb4:97:12
run@http://localhost:9876/base/node_modules/zone.js/dist/zone-microtask.js?87bbeaae4d01ebf513e1bbea41a0e13dbad92eb4:1217:29
zoneBoundFn@http://localhost:9876/base/node_modules/zone.js/dist/zone-microtask.js?87bbeaae4d01ebf513e1bbea41a0e13dbad92eb4:1194:29
lib$es6$promise$asap$$flush@http://localhost:9876/base/node_modules/zone.js/dist/zone-microtask.js?87bbeaae4d01ebf513e1bbea41a0e13dbad92eb4:236:18'
Finished in 0.023 secs / 0 secs

Thank you.


#2

at karma.config.js

add in file property the pattern

{ pattern: ‘node_modules/ionic-native/dist/**/*.js’, included: false, watched: false },

beside that, add in proxies property

‘/base’: ‘/base/node_modules/ionic-native/dist’,
’/base/ionic-native.js’: ‘/base/node_modules/ionic-native/dist/index.js’

Cheers!


#3

Yeah, I fixed it already. But thank you very match )

My code version:
files
{ pattern: 'node_modules/ionic-native/dist/ionic.native.js', included: false, watched: false, served: true}

proxies
'/base/ionic-native.js': '/base/node_modules/ionic-native/dist/ionic.native.js'


#4

You’re welcome.

I should change it for these config, to work properly:

proxies: {
// allows us to keep test code separate from app code and still have the references work
’/base/node_modules/ionic-framework/decorators/app.js’: ‘/base/www/build/test/app.stub.js’, // stub out Ionic’s @App decorator
’/base/www/build/app’: ‘/base/www/build/test’,
’/build’: ‘/base/www/build/test’,
’/base/plugins’: ‘/base/node_modules/ionic-native/dist/plugins’,
’/base/ionic-native.js’: ‘/base/node_modules/ionic-native/dist/index.js’,
’/base/ng1.js’: ‘/base/node_modules/ionic-native/dist/ng1.js’,
’/base/util.js’: ‘/base/node_modules/ionic-native/dist/util.js’
},