TDD and Marionette.Module pattern

248 views
Skip to first unread message

gumaflux

unread,
Feb 7, 2014, 4:59:14 AM2/7/14
to backbone-...@googlegroups.com
Hi 

This might be a bit off topic for this group, anyway:

I am TDDing a Marionette.Module and have a problem with the start time of the module in the mocha tests. I start the module in describe.before(), but of course the function returns prior to the module being started. I just wanted to see if there are any common patterns for implementing this or if I just solve this with a callback? 

I noticed that Jasmine has a waitsFor function, which would have been useful...

Thanks

Roberto Guerra

unread,
Feb 7, 2014, 9:09:17 AM2/7/14
to backbone-...@googlegroups.com
I personally don't use Marionette's modules. But if I were to use them, I would not put my views and controllers inside the module. I would require them inside the module and call them from there. That way I can unit test the controllers in isolation, without needing the modules. I'd probably only test the modules in a functional or integration test. They are too high level, in my opinion, to be unit tested.

Dustin Nation

unread,
Feb 7, 2014, 12:00:19 PM2/7/14
to backbone-...@googlegroups.com
I may not be understanding what you are trying to do, but when I create a module, I do all of its setup in its initializer.  Check out the"addInitializer" function


On Friday, February 7, 2014 3:59:14 AM UTC-6, gumaflux wrote:
Message has been deleted

Dustin Nation

unread,
Feb 7, 2014, 12:09:40 PM2/7/14
to backbone-...@googlegroups.com
For instance, I actually put regions inside my modules, so in my addInitializer function I set up my regionManageer, and then in addFinalizer I close all of the regions.

I may be wrong, but I think that the reason for this is that the module definition is a function that gets run on instantiation whereas a View definition is an object...or something like that :)

Giorgio Bozio

unread,
Feb 7, 2014, 7:25:54 PM2/7/14
to backbone-...@googlegroups.com
Not sure I understood your problem.
If the problem is testing async execution of module start, you can do simply this in mocha:

var mod = MyApp.module("MyMod")
before(function(done) {
  mod.on("start", function(){
    done()
  })
  mod.start()
}

Giorgio Bozio

unread,
Feb 7, 2014, 7:29:08 PM2/7/14
to backbone-...@googlegroups.com
Not sure I understood your problem.
If it is about testing async execution of module start, you can do this with mocha:

var mod = MyApp.module("MyMod")
before(function(done) {
  mod.on("start", function(){
    done()
  })
  mod.start()
}


gumaflux

unread,
Mar 25, 2014, 4:40:37 AM3/25/14
to backbone-...@googlegroups.com
Oops completely missed the replies here - yeah that's a much better way to do unit test the functionality. Thanks

gumaflux

unread,
Mar 25, 2014, 4:41:53 AM3/25/14
to backbone-...@googlegroups.com
Thanks - I was trying to test functionality in the module taht really should have been extracted into controllers aso. Thanks for the suggestion though
Reply all
Reply to author
Forward
0 new messages