2015-08-13 21 views
0

我試圖集成Jasmine(v2.3.4)爲骨幹js應用程序,根據一些示例和文檔中找到的淨。以下鏈接中提到了一些內容。茉莉花與骨幹集成導致 - 未捕獲TypeError:無法讀取HtmlReporter()中未定義的屬性'env'

http://kilon.org/blog/2012/08/testing-backbone-requirejs-applications-with-jasmine/ http://www.joezimjs.com/javascript/setting-up-a-jasmine-unit-testing-environment-with-testem/

所有步驟進行了明確實現,但我得到以下類型的錯誤「遺漏的類型錯誤:無法讀取屬性未定義‘ENV’」在茉莉花html.js HtmlReporter功能。

我看到HtmlReporter需要一個選項參數,但我不知道該傳遞給這個方法。感謝有關此主題的任何幫助。

我已經把下面的代碼在我需要的配置 - '茉莉花':{ 出口: '茉莉花' }, '茉莉花HTML':{ DEPS:[ '茉莉花'], 出口:「茉莉」 }, 「引導」:{ DEPS:[ 「茉莉」], 出口: '茉莉' }

要求([],函數(){

var jasmineEnv = jasmine.getEnv(); 
jasmineEnv.updateInterval = 1000; 

var htmlReporter = new jasmine.HtmlReporter(); // ***this is leading to Uncaught TypeError: Cannot read property 'env' of undefined*** 

jasmineEnv.addReporter(htmlReporter); 

jasmineEnv.specFilter = function(spec) { 
    return htmlReporter.specFilter(spec); 
}; 

var specs = []; 

specs.push('SearchSpec'); 


$(function(){ 
    require(specs, function(){ 
     jasmineEnv.execute(); 
    }); 
}); 

});

回答

1

嘗試 require.config({ paths:{ jasmine: 'path/jasmine', 'jasmine-html': 'path/jasmine-html', 'jasmine-boot': 'path/boot', }, shim:{ 'jasmine-html': { deps: ['jasmine'], }, 'jasmine-boot': { deps: ['jasmine', 'jasmine-html'], }, });

require(['jasmine-boot'], function() { require([ 'spec' ], function(){ //trigger Jasmine window.onload(); }); }); //spec.js define( ['path/to/module'], function(MyModule) { describe('test',function() {}) });

0
<script data-main="/js/main" src="/js/lib/require.js"></script> 
<script type="text/javascript"> 
    require([ 
     'test/spec/collections/companyCollection.spec', 
     'test/spec/models/companyDivisionsModel.spec' 
    ], function() { 
     window.onload(); 
    }); 

+0

非常容易和舒適的地方,這個碼到您的specRunner.html文件 –

相關問題