The code is part of a script for automated testing with the sencha test software which is based on selenium and jasmine and while the goal should be straight forward enough it proved to be quite difficult to get right. The code looks like this:
it('tests something', function(done) {
externalRef1.checkSomething(param1, param2, param3, param4)
.then(
function (result) {
externalRef2.clickSomething(param5, param6, result)
}
)
.then(done)
}, 30000)
Function "checkSomething":
function checkSomething (param1, param2, param3, param4) {
return new Promise(function (resolve) {
param1.timedout()
.and(function (future) {
//Some code
})
.execute(function () {
//More code
})
.and(function () {
//Even more code
})
.and(function (obj) {
resolve(obj.data) // obj.data will be a boolean
})
})
}
Function "clickSomething":
function clickSomething (param5, param6, param7) { //param7 receives result input
return new Promise(function (resolve, reject) {
if (param7 === false) {
param5.pageObject(param6).visible().click()
.and(function () {
resolve()
});
reject()
};
reject()
})
}
The code is simplified to what I assume could be relevant. Both functions are working correctly when executed alone and when the "clickSomething"-function is not wrapped within "function (result) {}" they are even working in the expected sequence ("clickSomething" running after "checkSomething" is finished). However, when the wrapping function is used to pass the result, "clickSomething" no longer runs in time.
From what I can gather by debugging, the "checkSomething" function is still working properly and its result value is indeed available to the "clickSomething" function, however the whole it-block just finishes before the content of "then()" even starts running.
What am I missing?