json - jsonarray.length behaving ambiguosly -
json - jsonarray.length behaving ambiguosly -
i have function returns jsonarray .
1) perform thatarray.length gives x
2) add together jsonelement array
3)i perform thatarray.length 1 time again gives (sometimes x , x+1). step done in separate function , variable in store result declared separately @ top of each function eliminate global thing
my uncertainty jsonarray.length might asynchronous phone call
if asynchronous phone call how wait till result achieved
i peforming checks through jasmine
thanks in advance
code:
it("getentities", function() { var no_of_entities; var metaservice = new metadataservice(true); fixture = metaservice.getmetadataprovider(); function successcallback(response) { if (response !== null && response !== undefined) { saas.print("getentities:successcallback"); no_of_entities = response.length; if (response.length !== null && response.length > 0) { test_entityname = response[0]["name"]; saas.print("response:"+json.stringify(response)); saas.print("--"+no_of_entities); } flag = true; } } function errorcallback(errror) { saas.print("getentities:errorcallback " + errror.errorcode + ":" + errror.errormsg); } runs(function() { fixture.getentities(session_token, successcallback, errorcallback); }); waitsfor(function() { homecoming flag; }, duration); runs(function() { expect(flag).tobe(true); expect(test_entityname).tobedefined(); expect(test_entityname).not.tobe(null); expect(no_of_entities).toequal(testconstants.total_entities_from_crm_imported); }); }); //author aditya //creation of custom table enterprisedb it("createcustomtableforenterprisedb", function() { function successcallback(response) { if (response !== null && response !== undefined) { saas.print("createcustomtableforenterprisedb:successcallback"); flag = true; saas.print("response:"+json.stringify(response)); } } function errorcallback(error) { saas.print("createcustomtableforenterprisedb:errorcallback"); saas.print("error code:"+error.errorcode+" errormessage:"+error.errormsg); } runs(function() { var metadata = new metadata(); metadata.createcustomtable(session_token,successcallback,errorcallback); }); waitsfor(function() { homecoming flag; },duration); runs(function() { expect(flag).tobe(true); }); }); //if custom table created additional table should come in no of entities it("getentitiesaftercustomtablecreation", function() { var no_of_entities; var metaservice = new metadataservice(true); fixture = metaservice.getmetadataprovider(); function successcallback(response) { saas.print("getentitiesaftercustomtablecreation:successcallback"); if (response !== null && response !== undefined) { flag = true; saas.print("response:"+json.stringify(response)); no_of_entities = response.length; saas.print("--"+no_of_entities); } } function errorcallback(error) { saas.print("getentitiesaftercustomtablecreation:errorcallback"); saas.print(error.errorcode+" "+error.errormsg); } runs(function() { fixture.getentities(session_token, successcallback, errorcallback); }); waitsfor(function() { homecoming flag; }, duration); runs(function() { expect(flag).tobe(true); expect(test_entityname).tobedefined(); expect(test_entityname).not.tobe(null); //expect(no_of_entities).toequal(testconstants.total_entities_from_crm_imported+1); }); });
json asynchronous arrays
Comments
Post a Comment