2015-04-27 78 views
-2

我想测试一个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

您的karma.conf会更好 –

+0

更新了karma.conf – BobDoleForPresident

+0

第一件事要解决的问题:使用角度和角度模拟的相同版本。 –

回答

0

问题原来是因为我没有将相应的bower_components加载到karma.conf.js中。更改为未缩小版本的角度允许我查看更多描述性错误,这些错误帮助我解决了这个问题。