Question

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.

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top