Parthasarathy Hd
Parthasarathy Hd

Reputation: 1

jasmine integration with backbone leads to - Uncaught TypeError: Cannot read property 'env' of undefined in HtmlReporter()

I am trying to integrate Jasmine (v2.3.4) for a backbone js application as per some examples and documentation found in the net. Some content used from the following links mentioned.

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/

All steps were clearly implemented but I am getting following type error "Uncaught TypeError: Cannot read property 'env' of undefined" in jasmine-html.js HtmlReporter function.

I see HtmlReporter takes a options param but I am not sure what to pass to this method. Appreciate any help on this topic.

I have put the following code in my require config - 'jasmine': { exports: 'jasmine' }, 'jasmine-html': { deps: ['jasmine'], exports: 'jasmine' }, "boot":{ deps:["jasmine"], exports: 'jasmine' }

require([], function(){

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();
    });
});

});

Upvotes: 0

Views: 612

Answers (2)

V.S.V
V.S.V

Reputation: 302

<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();
    });

Upvotes: 0

Pavel Noroc
Pavel Noroc

Reputation: 54

Try 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() {}) });

Upvotes: 1

Related Questions