Angular 模块测试不工作
Angular module test not working
我正在尝试测试 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 文件,请询问,我会进行更新。
问题原来是我没有将适当的 bower_components 加载到 karma.conf.js 中。更改为未缩小版本的 angular 让我看到更多描述性错误,帮助我解决了这个问题。
我正在尝试测试 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 文件,请询问,我会进行更新。
问题原来是我没有将适当的 bower_components 加载到 karma.conf.js 中。更改为未缩小版本的 angular 让我看到更多描述性错误,帮助我解决了这个问题。