我试图在使用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浏览器进行测试似乎没有拉入外部文件?
我可能会嘲笑整个谷歌地图对象,但似乎过度和不必要,因为它应该包含在指定的文件中。
如果有人有任何想法,我会非常感谢您的帮助。谢谢!