Problem
I'm using QUnit, and following this stackoverflow answer which seems to work in that scenario.
The data I attempt to supply to the 'success' method doesn't 'arrive' - it's not in the format required, or comes through as undefined. I can't see where I'm going wrong.
Walk-through
The 'unitTest' method that supplies my 'methodUnderTest' with a DOM element. The 'methodUnderTest' makes an jQuery ajax call, which is mocked in the unit test. Then success is called, and the result of the success method executing forms the unit test assert.
Code
I have set this up as a JSFiddle example here, if you would like to see the code executing (failing to execute as expected). But here is some of it, in case my mistake is very obvious:
//stubbing the ajax call
jQuery.ajax = function (param) {
options = param;
};
//the data
var expectedData = jQuery.parseJSON({
'id': 'fbs',
'fieldName': 'fbs',
'data': 'fbs-text'
});
//call to success method, in unit test
options.success({
sdata: expectedData,
textStatus: 'is-this-data-arriving',
jqXhr: 123
});
//the success method that is failing to get the expected data
function handleSuccess (sdata, textStatus, jqXhr) {
//problem is here not this success method never gets the data
console.log('sdata: ' + sdata + '|textStatus:' + textStatus + '|jq:' + jqXhr);
jQuery('#' + sdata.fieldName + '-loading').attr('alt', 'modified');
};