1

I was trying to write some javascript unit tests, using requirejs and jsTestDriver intellij plugin. When I run them in the IDE I have no error even when there are some. I only see them when opening my browser console. Did someone manage to make IDE plugin displays failures into a require function ? My code below and some screen shots illustrating my problem.

TestCase("Collections", {
    "test User Collection": function () {
        require(['lib/underscore', 'lib/backbone', 'app/user', 'app/collections'],
            function (_, Backbone, user, appCollections) {
                assertNotUndefined('Users must be defined', appCollections.users);
                assertTypeOf('Users must be backbone collection', typeof Backbone.Collection, appCollections.users);
                assertTypeOf("Users' model must be a user", typeof Backbone.Model, appCollections.users.model);
            });
    }
});

Intellij jsTestDriver plugin test result

My browser console

P. Ekouaghe
  • 214
  • 5
  • 10
  • js-test-driver and requirejs covered here - http://stackoverflow.com/questions/12482072/is-it-possible-to-run-js-test-driver-tests-that-uses-requirejs-modules. You must understand that the test your have written is probably async and therefore js-test-driver probably does not know that the test hasn't run before the test method returns. – Paul Grime Jun 20 '13 at 08:24
  • Thanks for your answer. It is actually async because when you add an instruction just after the require function, it is executed before any instruction inside the require function. Is there any mean to make it wait for the end of the whole execution? The link in your comment doesn't deal with this async problem. – P. Ekouaghe Jun 20 '13 at 11:50
  • Probably this page will help - http://code.google.com/p/js-test-driver/wiki/AsyncTestCase. – Paul Grime Jun 20 '13 at 12:23

1 Answers1

1

I haven't tested this, but it might get you started:

var CollectionsTest = AsyncTestCase('Collections');

CollectionsTest.prototype.testIt = function(queue) {

  queue.call('Step 1', function(callbacks) {

    function test1(_, Backbone, user, appCollections) {
        assertNotUndefined('Users must be defined', appCollections.users);
        assertTypeOf('Users must be backbone collection', typeof Backbone.Collection, appCollections.users);
        assertTypeOf("Users' model must be a user", typeof Backbone.Model, appCollections.users.model);
    }

    var onModulesLoaded = callbacks.add(test1);

    require(['lib/underscore', 'lib/backbone', 'app/user', 'app/collections'], onModulesLoaded);

  });

};
Paul Grime
  • 14,970
  • 4
  • 36
  • 58