Get help with testing, discuss unit testing strategies etc.


Post by lshengfa »

Hello,
I am considering loading json file from my local computer and then parse it to become an object so that I can use it as assert parameter.
var actual = 'abc';
var expect = load_from_local().parse_to_object();
t.is(actual, expect, 'succeed');
I think this can be loaded by
var req = Ext.Ajax.request({
        url : 'blah.json'   // Just grab some file
});
Is this the recommended way to do it, both locally and remotely? Is there other option in Siesta such as a file read?
Thank you.

Post by arcady »

Yes sure you can use AJAX to load files just keep in mind that file load happens asynchronously.
So you need to use pair of beginAsync and endAsync calls. Like this for example:
        // start asynchronous part
        var as  = t.beginAsync();
        
        Ext.Ajax.request({
            url         : url,
            callback    : function(options, success, response) {
                // notify that corresponding asynchronous part is complete
                t.endAsync(as);

                if (!success) t.fail('File [' + url + '] failed to load');

                var obj = Ext.JSON.decode(response.responseText, true);

                // assertions to validate obj
                ...
            }
        });

Post Reply