Requirement is to run testRunner function based on variable 'data' which is dependent on function 'getSteps'
My code as below
function getSteps()
it('test', async function () {
testStepsArray = await excel.getColValue('smoke.xlsx', 'Sheet1', 'A')
return testStepsArray
});
}
function testRunner(count) { **//i want to run this function based on value of data variable below**
it('test', async function () {
for(var j=0;j<count;j++)
{
...
}
});
}
var data = getSteps();
console.log(data.length+"LENGTH") **//returns Cannot read property 'length' of undefined.**
for(var i=1; i<= data.length;i+=count)
{
...
testRunner(i)
}
i think last block is not waiting for results of getSteps. Please suggest.
Update: After inputs, I modified as below and i see difference. I now can get data values properly but execution fails when there is a function wrapped around spec but works with regular function
function testRunner(count) {
it('test', async function () {
for(var j=0;j<count;j++)
{
...
}
});
}
function test(){
...
}
let promise = new Promise((resolve,reject)=>{
it('test', async function () {
testStepsArray = await excel.getColValue('smoke.xlsx', 'Sheet1', 'A')
resolve(testStepsArray)
});
}
})
promise.then((data)=>{
console.log(data.length+"LENGTH")
for(var i=1; i<= data.length;i+=count)
{
testRunner(i) //fails if function is like testrunner() - function wrraped around specs
test() //works if function is like test() - regular function
}
})
Update 2:Promise rejection Error logs
[32m. [0mError: 'it' should only be used in 'describe' function
at ensureIsNotNested (\nodejs\node_modules\jasmine_3.5.0\node_modules\jasmine-core\lib\jasmine-core\jasmine.js:1786:15)
at Env.it (\nodejs\node_modules\jasmine_3.5.0\node_modules\jasmine-core\lib\jasmine-core\jasmine.js:1933:7)
at it (nodejs\node_modules\jasmine_3.5.0\node_modules\jasmine-core\lib\jasmine-core\jasmine.js:6576:21)
at testRunner (webapps\mysamples\testRunner.js:66:4)
at webapps\mysamples\testRunner.js:59:4
at processTicksAndRejections (internal/process/task_queues.js:97:5)