2

My question is: what's the best way to know when a child module has fully loaded and finished composition, so that i can then test the html contents of that module?

I'm trying to write some integration tests that run after a route has fully finished composition.
So, the way I have the tests structured, is:
Right before the 'navigate()' call, i attach:
router.on('router:navigation:composition-complete', callback)
Next I call:
router.navigate('parent/child')
And my test code is in the callback for 'router:navigation:composition-complete'

The problem is, the route is calling a child route. That is, a parent route, that points to a module which loads up child routes. The routing works fine in my application, but when i listen for the 'router:navigation:composition-complete' event in my tests, the event fires immediately after the parent module loads, before the child module has even loaded.
Also, this only happens for the second test. By that I mean, if i have one test that navigates to a route, the event fires after the child module has loaded correctly. Then after that test has run, if i then, in a new test, navigate to a new route so i can test that, the event only fires immediately after the parent module has loaded.

SO, how can i properly know when the child module has fully finished composition, so that i can then test the html contents of my module?

Here's an example of how my routes are structured, to give a better idea of the problem I see:

    router.map([
        /*{durandal:routes}*/
        {"route": 'parent*details',"moduleId":"parent/index","title":"Parent", hash: '#parent'}
    ]).buildNavigationModel();

And then in parent/index.js I have this:

var childRouter = router.createChildRouter()
    .makeRelative({
        moduleId:'',//refers to the 'parent' folder
        fromParent: true
    })
    .map([
        { route: 'child', moduleId: 'parent/viewmodels/child', title: 'Child', type: 'intro', nav: true}
    ]).buildNavigationModel();

So then if I call: router.navigate('parent/child') it is firing the composition-complete event immediately after parent/index.js loads instead of when parent/viewmodels/child.js loads.

Tyler Jones
  • 1,283
  • 4
  • 18
  • 38

1 Answers1

1

I'm not sure if this : Durandal router / lifecycle events when using a childRouter can help you here but I think the idea is the same

Community
  • 1
  • 1
Adel Sal
  • 718
  • 5
  • 16
  • 1
    Brilliant! That's exactly what I needed to do! I had to grab the child router after the parent had fired the event, then listen for the event on the child router. How did you know about the child, parent, context signature of the composition-complete callback? – Tyler Jones Apr 01 '14 at 06:19
  • @TylerJones I was facing a similar problem then I had to dig deep in the durandal router.js source code, then that's where I found it. Glad I could help.:) – Adel Sal Apr 01 '14 at 07:13