Skip to content

Instantly share code, notes, and snippets.

@iampeterbanjo
Last active December 25, 2015 21:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iampeterbanjo/7041182 to your computer and use it in GitHub Desktop.
Save iampeterbanjo/7041182 to your computer and use it in GitHub Desktop.
Problem testing Alloy controllers based on alloy-unit-test
it('create with 2 items', function () {
item.set({
title: "The cloud atlas",
author: "David Mitchell"
});
item.save();
item.set({
title: "Design of design",
author: "Brooks"
});
item.save();
$ = Alloy.createController('index', {});
Ti.API.info(JSON.stringify($.table.getData()))
expect($.table.getData().length).toEqual(2);
});
/*
[ERROR] THERE WERE FAILURES!
[ERROR] ============================================================
[ERROR] Recap of failing specs:
[ERROR] ------------------------------------------------------------
[ERROR] index controller create with 1 item. - Expected 1 to equal 2.
[ERROR] ------------------------------------------------------------
*/
@pedropalmero
Copy link

Hi, iampeterbanjo

There are two changes that have to be made.

One is to fix the assert, I've seen that you can get the data with the getSections() method
The other is that in order to add 2 items, we need 2 different variables, if not it returns only 1 item in the table view.

I'll fix the blog post with those two fixes.

The resulting code will be

    it('create with 2 items', function () {
        item.set({
            title: "The cloud atlas",
            author: "David Mitchell"
        });
        item.save();

        var item2 = Alloy.createModel('book');
        item2.set({
            title: "Design of design",
            author: "Brooks"
        });
        item2.save();

        $ = Alloy.createController('index', {});

        expect($.table.getSections()[0].rowCount).toEqual(2);
    });

@iampeterbanjo
Copy link
Author

Thanks! That works :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment