I am trying to run my unit tests for Typescript class, but I am getting an error about missing Promise when connected to PhantomJS browser. Below I attach some configuration I am using. What I want to achieve is to write tests in Typescript and use ES6 features like imports and arrow functions.
karma.conf.js
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['systemjs', 'jasmine'],
plugins: [
'es6-module-loader',
'karma-systemjs',
'karma-jasmine',
"karma-spec-reporter",
"karma-phantomjs-launcher"
],
files: [
'app/test/**/*.spec.ts',
],
systemjs: {
configFile: './karma.system.conf.js',
config: {
baseURL: './'
},
serveFiles: [
]
},
exclude: [],
preprocessors: {},
reporters: ['spec'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['PhantomJS'],
singleRun: true,
concurrency: Infinity
})
}
karma.system.conf.js
System.config({
paths: {
'es6-module-loader': 'node_modules/es6-module-loader/dist/es6-module-loader.js',
'jasmine': 'node_modules/karma-jasmine/*',
systemjs: 'node_modules/systemjs/dist/system.js',
typescript: 'node_modules/typescript/lib/typescript.js',
'plugin-typescript': 'node_modules/plugin-typescript/lib/plugin.js'
},
meta: {
'*.ts': {
format: 'es6'
}
},
packages: {
'app/': { defaultExtension: 'ts' }
},
transpiler: 'typescript',
});
'karma start' output
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
ReferenceError: Can't find variable: Promise
at node_modules/systemjs/dist/system.js:5
PhantomJS 2.1.1 (Mac OS X 0.0.0): Executed 0 of 0 ERROR (0.042 secs / 0 secs)
PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR LOG: 'Error: Not setup properly. window.Promise is undefined'
Do anyone has an idea what is wrong with that setup?