0

I'd like to test the binding of a durandal view to it's viewmodel; to ensure that the property names on the view and viewmodel are in sync.

Ideally using the durandal composition engine in order to include any plugins that are enabled (mainly observable).

Is there any examples available? (I can't find anything) Is there a more durandal way than just getting the view and calling ko.applyBindings?

Update:

This is what I currently am doing, binding errors are throw for mismatches, then I can use the bound view to test expected elements.

beforeEach(function(done) {

    var me = this;


    require(['durandal/viewLocator', 'knockout', 'durandal/binder', 'viewmodels/category', "underscore"], function(viewLocator, ko, binder, vm, _){
        me._ = _;


        binder.throwOnErrors = true;
        viewLocator.locateView('views/category').then(function(view){

                me.view = view;
                me.viewModel = vm;
                me.viewModel.categories = [
                            {id:1, name:"Test 1",enabled:true},
                            {id:2, name:"Test 2",enabled:false}
                ];

                ko.cleanNode(me.view);
                //This will throw if any name mismatches the viewmodel
                binder.bind(vm, view);
                done();

        });

    });

});
Adam Mills
  • 7,719
  • 3
  • 31
  • 47
  • It's not very clear what you are trying to achieve. Do you want to unit test the framework features itself? Then look at the Github Repo and tests like [Binder.Spec](https://github.com/BlueSpire/Durandal/blob/master/test/specs/binder.spec.js) or is it something different? Could you maybe provide a mockup of what you would like to do? – zewa666 Jun 28 '14 at 09:14
  • have a look at Testing with PhantomJS and Jasmine http://durandaljs.com/documentation/Testing-With-PhantomJS-And-Jasmine.html – Gildas.Tambo Jun 28 '14 at 09:42

0 Answers0