This is a migrated thread and some comments may be shown as answers.

Best way to check that properties of an observable are observable

2 Answers 97 Views
MVVM
This is a migrated thread and some comments may be shown as answers.
Jack
Top achievements
Rank 2
Iron
Jack asked on 05 Feb 2015, 07:32 PM
The following test works (using http://mochajs.org + http://chaijs.com):

it('Test composition', function() {
    var viewModel = kendo.observable({
        obj1: {
            obj2: {
                prop: 'test'
            }
        }
    });
    expect(viewModel).to.be.an.instanceof(kendo.Observable);
    expect(viewModel.obj1).to.be.an.instanceof(kendo.Observable);
    expect(viewModel.obj1.obj2).to.be.an.instanceof(kendo.Observable);
});

The following test fails:

it('Test submodels', function() {
    var Item = kendo.data.Model.define({
        fields: {
            title: {
                type: 'string'
            },
            attributes: {
                defaultValue: {}
            }
        }
    });
    var Attributes = kendo.data.Model.define({
        fields: {
            src: {
                type: 'string'
            },
            alt: {
                type: 'string'
            },
            style: {
                type: 'string'
            }
        }
    });
    var attributes = new Attributes({alt: 'Google', src: 'http://www.google.com/logo.jpg', style: 'height: 100px; width: 100px;'}),
        item = new Item({title:'sample image', attribute: attributes}),
        viewModel = kendo.observable({ item: item });
    expect(viewModel.item).to.be.an.instanceof(Item);
    expect(viewModel.item).to.be.an.instanceof(kendo.data.Model);
    expect(viewModel.item).to.be.an.instanceof(kendo.Observable);
    expect(viewModel.item.attributes).to.be.an.instanceof(Attributes);        //Fails
    expect(viewModel.item.attributes).to.be.an.instanceof(kendo.data.Model);  //Fails
    expect(viewModel.item.attributes).to.be.an.instanceof(kendo.Observable);  //Fails
});

How can I at least test that viewModel.item.attributes is an observable? Otherwise what instance of is it?







2 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 09 Feb 2015, 04:35 PM
Hello,

I think you should try this:
item = new Item({title:'sample image', attributes: attributes})

your original code is missing an "s".

Once you do this things should work as expected: http://dojo.telerik.com/@korchev/eGOza
Regards,
Atanas Korchev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Jack
Top achievements
Rank 2
Iron
answered on 10 Feb 2015, 10:15 AM
I feel so bad as this was so obvious. Thank you. 
Tags
MVVM
Asked by
Jack
Top achievements
Rank 2
Iron
Answers by
Atanas Korchev
Telerik team
Jack
Top achievements
Rank 2
Iron
Share this question
or