With a little modified version of the pollUntil function multiple async conditions using normal expectations could be supported. Since those expect() call always throw an informative assertion-error, it could be used also as more helpful test-error message.
var i = 0;
Meteor.setInterval(function () {
i++;
}, 100);
until(
waitFor,
function () {
expect(i).to.equal(10);
});
until(
waitFor,
function () {
expect(i).to.equal('A');
});
This example has two conditions, where the last one will never be true and result in a timeout with
timeout after 4800ms waiting for: expected 48 to equal 'A'
One problem is still the "global-test-timeout", which after 5s terminates the test with Async batch timed out. The detailed error messages are only visible when they timeout little earlier.
Even more better to read could be
waitFor.condition(function () {
expect(i).to.equal(10);
})
This would need some changes in the ExpectationManager.
Here is the until function.
until = function (expect, condition, timeout) {
var step = 100;
var start = (new Date()).valueOf();
timeout = timeout || 4800;
var lastError;
var complete = expect(function (error) {
if (error) {
throw new Error('timeout after ' + timeout + 'ms waiting for: ' + lastError.message);
}
});
var helper = function () {
try {
condition();
complete();
return;
}
catch (e) {
lastError = e;
}
if (start + timeout < (new Date()).valueOf()) {
complete(true);
return;
}
Meteor.setTimeout(helper, step);
};
helper();
};
With a little modified version of the pollUntil function multiple async conditions using normal expectations could be supported. Since those expect() call always throw an informative assertion-error, it could be used also as more helpful test-error message.
This example has two conditions, where the last one will never be true and result in a timeout with
One problem is still the "global-test-timeout", which after 5s terminates the test with
Async batch timed out. The detailed error messages are only visible when they timeout little earlier.Even more better to read could be
This would need some changes in the ExpectationManager.
Here is the
untilfunction.