Brian Barnes
Brian Barnes

Reputation: 1027

How can we use jasmine, jasmine.ConsoleReporter, require.js and backbone together

I'm struggling to get jasmine along with it's ConsoleReporter working within a backbone application using require.js. I have seen Check Backbone/requireJs project with Jasmine but that hardcodes the libraries (which is something that I'd prefer to avoid).

In my backbone application I have created test function (I'd prefer to keep it there to test interactions between models):

test = function () {
    require(['js/test/run'], function () {});
}

and run.js (I get the console.log "should" fine, but don't get anything to do with the failed test):

define(["jasmine", "jasmineConsoleReporter"],
function (jasmine, ConsoleReporter) {

    describe('hello', function () {
        it('should be true', function () {
            console.log('should');
            expect(true).toEqual(true);
        });
    });

    jasmine.getEnv().addReporter(new ConsoleReporter(console.log));

    jasmine.getEnv().execute();

    //return tests;
}
);

The shim for jasmine and jasmineConsoleReporter are:

jasmine: {
    exports: "jasmine"
},
jasmineConsoleReporter: {
    deps: ['jasmine'],
    exports: "getJasmineRequireObj"
}

And the source for jasmineConsoleReporter can be found at https://github.com/pivotal/jasmine/blob/master/src/console/console.js

I'm guessing that the console reporter isn't being constructed correctly because I get the 'should' in the console and nothing else.

Upvotes: 2

Views: 1407

Answers (1)

Wojciech Szela
Wojciech Szela

Reputation: 166

Try my setup:

https://github.com/wojciechszela/jasmine-requirejs-jscover

Adding backbone to it (or any other lib) should be easy.

Upvotes: 0

Related Questions