2015-08-13 83 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文件 –

相关问题