2015-04-27 124 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中。更改爲未縮小版本的角度允許我查看更多描述性錯誤,這些錯誤幫助我解決了這個問題。