Get help with testing, discuss unit testing strategies etc.


Post by brownmonk »

Edit: Pretty sure this has to do with a callback issue. How do I test a function that has a callback?

function a {
obj.someFunction({callback: function b(){
//load store
}
}


How do I call function a from my test and then test that the thing that happened inside the callback function b worked? Just a time delay I guess?


Also, this is still weird behavior:


So... this is weird. When I log my store in the console inside a test it shows me something like this:

console.log(myStore)
Ext.Class.newClass
-data: Ext.Class.newClass
-events: Object
-eventsSuspended: false
-filters: Ext.Class.newClass
-groupers: Ext.Class.newClass
-loading: false
-model: function () {
-modelDefaults: Object
-proxy: Ext.Class.newClass
-removed: Array[0]
-sorters: Ext.Class.newClass
-storeId: "AllActivities"
-totalCount: 14
-__proto__: Class.registerPreprocessor.prototype
but if I do console.log(myStore.totalCount) it shows undefined.

If I expand myStore.data it shows a length property of 14, but if I log myStore.data.length is displays as 0.

t.is(myStore.data.length, 14, 'Loaded 14 records'); fails because of this. Any ideas here? I'm baffled.



StartTest(function (t) {

var button = Ext.getCmp('btnLogin');
t.ok(button, 'button ok');
console.log(button);
t.click(button.btnEl);


var controller = MyApp.app.getController('MyApp.desktop.controller.ActivityController');
var store = Ext.getStore('AllActivities');

console.dir('about to call loadActivities');
controller.loadActivities();
console.dir('called loadActivities');

console.log('store:');
console.log(Object.keys(store));
console.log(store); // Shows a property, totalCount, in the console with a value of 14
console.log(store.totalCount); // undefined (???)
console.log(store.data); // store.data.length shows 14
console.log(store.data.length); // 0???
t.is(store.data.length, 14, 'Loaded 14 records');


/*
Ext.Ajax.request({
url: 'https://localhost:8001/api/resource',

success: function (response, opts) {
var obj = Ext.decode(response.responseText);
console.dir(obj);
t.ok(response, "got response");
},

failure: function (response, opts) {
t.fail("request failed");

t.endAsync(async);
}
});
*/

t.done();

});

Post by marogalli »

Maybe the store was not loaded when u got the results.

There is function t.waitForStoresToLoad that can help, but no clue how to use it in your code.

Post by brownmonk »

Solved this like this:
    t.waitFor(
        function() {
            return myStore.getTotalCount() != undefined;
        },
        function(){
            t.is(myStore.getTotalCount(), 14, 'Loaded 14 records');
            t.done();
        });

Post Reply