This question and answer is very relevant as of today (soon 2018, > angular2, @angular/cli, typescript, ...).
Here is a small update, based on what i found as useful on the net:
Say you have an angular cli
generated project that has not been tempered with. Say you want to use PhantomJS
to run your angular2 tests (nothing shocking).
Start by installing PhantomJS
launcher for Karma in your project
npm i --save-dev karma-phantomjs-launcher
Next you have to update the karma.conf.js
file as follows:
First the the plugins properties:
plugins: [
require('karma-jasmine'),
require('karma-phantomjs-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular/cli/plugins/karma')
],
Then the browser properties
browsers: [ 'PhantomJS' ],
Running the test at this point, you will probably stumble on the following error:
PhantomJS 2.1.1 (Windows 7 0.0.0) ERROR
TypeError: pre,template,textarea,script,style is not iterable!
at http://localhost:9876/_karma_webpack_/polyfills.bundle.js:792
Basically, that means your PhantomJS
needs different polyfills. Uncomment the following lines in your src\polyfills.ts
import 'core-js/es6/symbol';
import 'core-js/es6/object';
import 'core-js/es6/function';
import 'core-js/es6/parse-int';
import 'core-js/es6/parse-float';
import 'core-js/es6/number';
import 'core-js/es6/math';
import 'core-js/es6/string';
import 'core-js/es6/date';
import 'core-js/es6/array';
import 'core-js/es6/regexp';
import 'core-js/es6/map';
import 'core-js/es6/weak-map';
import 'core-js/es6/set';
Last but not least, here are the links that helped me work this out:
How to run jasmine tests without browser ?
New angular-cli app not working on iphone 4s