我有一个返回jsonarray的函数。
1)我执行了aarray.length,它给出了x
2)我向数组添加了一个JSONelement
3)我再次执行thatarray.length(有时x和x + 1)。这个步骤是在一个完成的 单独的函数和我存储结果的变量在每个函数的顶部单独声明,以消除全局事物
我怀疑Jsonarray.length可能是异步调用
如果是异步调用,如何等到达到结果
我正在通过茉莉花进行检查
提前致谢
代码:
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() {
return 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 for 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() {
return flag;
},duration);
runs(function() {
expect(flag).toBe(true);
});
});
//If custom table is created additional table should come in the 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() {
return 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);
});
});