How do you use Istanbul Code Coverage with transpiled Typescript?

TL;DR: There is a tool: https://github.com/SitePen/remap-istanbul described as A tool for remapping Istanbul coverage via Source Maps The article on Sitepan describes it in more detail: Intern as well as other JavaScript testing frameworks utilise Istanbul for their code coverage analysis. As we started to adopt more and more TypeScript for our own projects, we … Read more

Karma, PhantomJS and es6 Promises

You can pull in the Babel polyfill by simply installing Babel Polyfill: npm install –save-dev babel-polyfill and then include the polyfill file before your source and test files within the files section of your karma.conf.js: files: [ ‘node_modules/babel-polyfill/dist/polyfill.js’, ‘index.js’, //could be /src/**/*.js ‘index.spec.js’ //could be /test/**/*.spec.js ], Unless you know that all your target browsers … Read more

How do unit test with angular-translate

it’s a known issue, please follow the documentation here: unit testing angular The solution Unfortunately, this issue is caused by the design of angular-translate. To get around these errors, all we can do is to overwrite our module configuration in our test suite, that it doesn’t use asynchronous loader at all. When there’s no asynchronous … Read more

AngularJS Promise Callback Not Trigged in JasmineJS Test

TL;DR Call $rootScope.$digest() from your test code and it’ll pass: it(‘should return false if user is not logged into Facebook’, function () { … var userLoggedIn; inject(function (Facebook, $rootScope) { Facebook.getUserLoginStatus($rootScope).then(function (data) { console.log(“Found data!”); userLoggedIn = data; }); $rootScope.$digest(); // <– This will resolve the promise created above expect(userLoggedIn).toEqual(false); }); }); Plunker here. Note: … Read more

How do I exclude files from karma code coverage report?

You can use several techniques here: karma uses minimatch globs for file paths and use can take advantage of that to exclude some paths. As first solution I’d say try to add only the paths of the file to preprocess with the coverage: // karma.conf.js module.exports = function(config) { config.set({ files: [ ‘src/**/*.js’, ‘test/**/*.js’ ], … Read more