Javascript Leadfoot的pollUntil()在变量值更改时未触发?
我目前正在实习生中编写功能测试,遇到了一个小问题 在测试套件的before部分中,我对API进行ajax调用以检索变量的值。设置这个变量对于功能测试的下一步至关重要,因此我想暂停测试,直到ajax调用返回该变量为止 我读到了Leadfoot的pollUntil功能,它听起来像是做了我需要做的事情。我编写了以下代码:Javascript Leadfoot的pollUntil()在变量值更改时未触发?,javascript,intern,leadfoot,Javascript,Intern,Leadfoot,我目前正在实习生中编写功能测试,遇到了一个小问题 在测试套件的before部分中,我对API进行ajax调用以检索变量的值。设置这个变量对于功能测试的下一步至关重要,因此我想暂停测试,直到ajax调用返回该变量为止 我读到了Leadfoot的pollUntil功能,它听起来像是做了我需要做的事情。我编写了以下代码: var valueThatChanges = 0; // ... (some functional test setup stuff) //Ajax call that sets
var valueThatChanges = 0;
// ... (some functional test setup stuff)
//Ajax call that sets value of valueThatChanges
.then(function() {
return ajaxCall(valueThatChanges);
})
//valueThatChanges is initially 0 before/during ajax call
//Is set to a randomly generated value that is non-zero after response recieved
.then(pollUntil(function(valueThatChanges) {
return valueThatChanges !== 0 ? true : null;
},[valueThatChanges], 30000, 100))
.then(function() { //On success
console.log('Value is no longer zero.')
}, function(error) { //On failure/timeout
console.log(error)
})
});
但是,这不起作用,因为函数立即进入成功回调,尽管valueThatChanges的值仍然为0
我知道PollTill可能不适合处理这样的情况,因为我没有直接处理PollTill中的DOM元素,但我不确定为什么它不适合这种特定场景
似乎PollTill没有在每次调用其轮询函数时传递更新的变量
PollTill是否可以处理在变量值更改时触发事件?PollTill的一般使用情况是,您需要等待远程浏览器中发生某些事情。例如,PollTill通常用于等待功能测试页完全初始化:
// ---------------------
// functional test (in Node.js)
this.remote.get('testpage.html')
.then(pollUntil('return window.pageIsReady ? true : null'))
// rest of test
// ---------------------
// remote test page (in the browser)
<script>
var pageIsReady = false;
require( ..., function ( ... ) {
// do setup stuff
pageIsReady = true;
});
</script>
var valueThatChanges;
registerSuite({
before: function () {
return new Promise(function (resolve) {
// Assuming ajaxCall calls a callback when it's finished:
ajaxCall(function (newValue) {
valueThatChanges = newValue;
resolve();
});
});
},
test1: function () {
return this.remote
// rest of test
},
// ...
});