Best way to check that properties of an observable are observable

3 posts, 0 answers
  1. Jack
    Jack avatar
    100 posts
    Member since:
    Jan 2007

    Posted 05 Feb 2015 Link to this post

    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. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 09 Feb 2015 Link to this post

    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!
     
  3. Kendo UI is VS 2017 Ready
  4. Jack
    Jack avatar
    100 posts
    Member since:
    Jan 2007

    Posted 10 Feb 2015 in reply to Atanas Korchev Link to this post

    I feel so bad as this was so obvious. Thank you. 
Back to Top