我正在尝试测试angularjs应用。我设法在笔记本电脑上运行了一些基本测试。这些测试只是检查模块并检查一些基本功能。这适用于我的笔记本电脑。但是,当我将测试环境移动到本地服务器时,测试将停止工作。例如,无论我传递的模块名称是什么,测试仍然通过。我还没有尝试过测试任何功能。只是模块测试。
app.js:
var app = angular.module('mcqsApp', []);
simpleTest.js:
describe('SimpleService test', function(){
beforeEach(function(){
module('blah');
});
it('SimpleService should have a module',function(){
});
});
karma.conf.js:
module.exports = function(config){
config.set({
// root path location that will be used to resolve all relative paths in files and exclude sections, should be the root of your project
basePath : '../',
// files to include, ordered by dependencies
files : [
// include relevant Angular files and libs
'https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.15/angular-mocks.js',
// include js files
'../../../public/js/app.js',
'../../../public/js/services/*/*.js',
// include unit test specs
'test/unit/services/*.js'
],
// files to exclude
exclude : [
],
// karma has its own autoWatch feature but Grunt watch can also do this
autoWatch : true,
// testing framework, be sure to install the karma plugin
frameworks: ['mocha', 'chai'],
// browsers to test against, be sure to install the correct karma browser launcher plugin
browsers : ['PhantomJS'],
// progress is the default reporter
reporters: ['mocha'],
// map of preprocessors that is used mostly for plugins
preprocessors: {
},
// list of karma plugins
plugins : [
'karma-junit-reporter',
'karma-chrome-launcher',
'karma-firefox-launcher',
'karma-mocha',
'karma-chai',
'karma-sinon',
'karma-mocha-reporter',
'karma-phantomjs-launcher'
]
})}
据我了解,如果模块名称不匹配,则应该失败。但无论模块名称如何,此测试都将通过。任何帮助将不胜感激。如果你们需要看到更多的代码,例如我的karma.conf.js文件,请询问,我会进行更新。
答案 0 :(得分:0)
问题结果是我没有在适当的bower_components中加载到karma.conf.js中。更改为非缩小版角度允许我看到更具描述性的错误,这有助于我解决这个问题。