Code Coverage for Unit Tests in Ionic

Hi Team

I I doing unit test cases in Ionic app but facing problem when trying to get code coverage.

Expected Behaviour

When I run command npm test --code-coverage then it should create coverage folder in root of project and inside that folder index.html file should created which will show code coverage

What I have done:

1.Tried in current project but its not working and giving some random error about module not added in entrycomponent. I have checked 2 times all files everything is correct

2.Create new project of Angular. In that project coverage project already created and its working

3.Create new project of Ionic with latest Ionic cli but their also no coverage folder created .

Overall no code coverage working in Ionic and also no coverage folder created in Ionic.

npm run test working perfectly in Ionic projects


when trying

npm run test-coverage command then its giving just success and failure test case

Took reference from below links but nothing worrks




If anyone knows solution please respond.


The problem is with your karma.conf.js
In my case my karma.conf.js had the dir as: dir: require('path').join(__dirname, '../coverage'),
If yours is just like mine all you need to do is to change from dir: require('path').join(__dirname, '../coverage'), to dir: require('path').join(__dirname, './coverage'), removing one of the two dots there are since the base href is already ./