我試圖在使用Karma的Chrome瀏覽器中運行測試。我一直在PhantomJS上運行它們,沒有任何問題,但希望切換到ChromeHeadless。我發現測試沒有通過Chrome或ChromeHeadless,但仍然通過使用PhantomJS。Karma Chrome測試在Chrome中失敗,但傳入PhantomJS
我相信它與配置中包含的文件有關。我認爲PhantomJS正在按預期加載它們,但由於某種原因,Chrome並非如此。我在這裏查看了其他問題,但解決方案並不特別相關,不幸的是沒有工作。
這是試圖使用Chrome運行我的測試時,我得到的錯誤:
Uncaught TypeError: Cannot read property 'maps' of undefined
這是指google.maps
,從window.google
,應在karma.conf.js
的文件中得到聲明得出:
module.exports = function(config) {
config.set({
// autoWatch: true,
browserConsoleLogOptions: {
terminal: true,
level: ''
},
// Prevent timeout issues when running the tests
browserDisconnectTimeout: 10000,
browserDisconnectTolerance: 3,
browserNoActivityTimeout: 60000,
browsers: ['Chrome'],
captureTimeout: 2000,
// debug: true,
files: [
'http://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js',
'http://maps.googleapis.com/maps/api/js?client=client_id',
{ pattern: 'test-context.js', watched: false }
],
frameworks: ['jasmine'],
// logLevel: config.LOG_DEBUG,
port: 9876,
preprocessors: {
'test-context.js': ['webpack'],
},
reporters: ['progress', 'spec'],
singleRun: true,
webpack: require('./webpack/config.test'),
webpackServer: {
noInfo: true
},
});
};
有誰知道我可能會做錯什麼,或者爲什麼運行Chrome瀏覽器進行測試似乎沒有拉入外部文件?
我可能會嘲笑整個谷歌地圖對象,但似乎過度和不必要,因爲它應該包含在指定的文件中。
如果有人有任何想法,我會非常感謝您的幫助。謝謝!