After upgrading the application to rc-7 and running my unit tests to make sure nothing broke, I received this error message in about half of my unit tests.
“Error: Zone.js detected that ZoneAwarePromise '(window | global) .Promise' has been overwritten. Most likely, the reason is that Promise polyfill was loaded after Zone.js (Polyfilling Promise api is not required when loading zone.js. If you must download it, do this before loading zone.js) in node_modules / zone.js / dist / zone.js (line 21) "
The closest I can think of is that I mock answers to http calls in my unit tests by manually returning observables.
This is an Angular2 application using Jasmine and Karma for unit testing.
UPDATE
Thus, it looks like this is probably the problem with loading according to the error message, however I do not load the poly regiments anywhere I can determine if I accidentally capture them. I attached my karma.conf.js and systemjs.conf.js to help find the error.
Karma.conf.js
module.exports = function(config) {
var gulpConfig = require('../gulp/config')();
var dependencies = [
'@angular',
'lodash',
'rxjs'
];
var configuration = {
basePath: '../../',
browserNoActivityTimeout: 20000,
frameworks: ['jasmine'],
browsers: ['PhantomJS'],
reporters: ['progress', 'coverage'],
preprocessors: {},
coverageReporter: {
includeAllSources: true,
dir: 'coverage/appCoverage/remap/',
reporters: [
{ type: 'json', subdir: 'report-json' }
]
},
files: [
'node_modules/reflect-metadata/Reflect.js',
'node_modules/zone.js/dist/zone.js',
'node_modules/zone.js/dist/long-stack-trace-zone.js',
'node_modules/zone.js/dist/proxy.js',
'node_modules/zone.js/dist/sync-test.js',
'node_modules/zone.js/dist/jasmine-patch.js',
'node_modules/zone.js/dist/async-test.js',
'node_modules/zone.js/dist/fake-async-test.js',
'node_modules/angular/angular.js',
'node_modules/core-js/client/shim.min.js',
'node_modules/systemjs/dist/system.src.js'
],
proxies: {
"/src/": "/base/src/",
"/app/": "/base/src/app/",
"/node_modules/": "/base/node_modules/"
},
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
};
configuration.preprocessors[gulpConfig.tmpApp + '**/!(*.spec)+(.js)'] = ['coverage'];
configuration.preprocessors[gulpConfig.tmpApp + '**/*.js'] = ['sourcemap'];
configuration.preprocessors[gulpConfig.tmpTest + '**/*.js'] = ['sourcemap'];
var files = [
gulpConfig.tmpTest + 'test-helpers/global/**/*.js',
gulpConfig.src + 'systemjs.conf.js',
'config/test/karma-test-shim.js',
createFilePattern(gulpConfig.tmpApp + '**/*.js', { included: false }),
createFilePattern(gulpConfig.tmpTest + 'test-helpers/*.js', { included: false }),
createFilePattern(gulpConfig.app + '**/*.html', { included: false }),
createFilePattern(gulpConfig.app + '**/*.css', { included: false }),
createFilePattern(gulpConfig.app + '**/*.ts', { included: false, watched: false }),
createFilePattern(gulpConfig.tmpApp + '**/*.js.map', { included: false, watched: false })
];
configuration.files = configuration.files.concat(files);
dependencies.forEach(function(key) {
configuration.files.push({
pattern: 'node_modules/' + key + '/**/*.js',
included: false,
watched: false
});
});
if (process.env.APPVEYOR) {
configuration.browsers = ['IE'];
configuration.singleRun = true;
configuration.browserNoActivityTimeout = 90000;
}
config.set(configuration);
function createFilePattern(path, config) {
config.pattern = path;
return config;
}
}
UPDATE
My solution implied that all of my zone.js files were loaded last in karma.conf.js. I assume that something else that I included also included polyfill, but it loaded after zone.js, so the error was raised. After moving zone.js to the end, everything worked fine.