How to mock an AJAX call?

Hi,

we are trying to develop tests for our modules and would like to mock an Ajax call. We have tried to do something like this:

Code:
AjaxMock = {
init : function (responseText) {
this.reset();
Ext.Ajax.on(‘beforerequest’, function (conn, options){
conn.responseText = responseText || ‘’;
options.success.apply(null, arguments);
conn.abort(conn.transId);
return false;
});
},

reset : function () {
    Ext.Ajax.purgeListeners();
}

};
But this did not work as intended. Any help would be appreciated on how to mock the response text and stop the outbound connection.