From: Nicolas Coden Date: Fri, 18 May 2018 20:13:04 +0000 (+0200) Subject: test: wait for debounce for slow browsers in Interval debounce test X-Git-Tag: v6.6.0~3^2~178^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ad2a282e6e20f80dd49e399178c47a6e3efeec3c;p=thirdparty%2Ffoundation%2Ffoundation-sites.git test: wait for debounce for slow browsers in Interval debounce test Timeout delays are most often not respected and the differences between several timeouts running in parrallel can be huge. To prevent race conditions on slower browsers, we run the debounce test several time to wait for the debounced event to be called, which may be finally called way after the expected time. --- diff --git a/test/javascript/components/interchange.js b/test/javascript/components/interchange.js index 5ef9fd9a3..a08b2bca5 100755 --- a/test/javascript/components/interchange.js +++ b/test/javascript/components/interchange.js @@ -1,4 +1,4 @@ -describe('Interchange', function() { +describe('Interchange', function () { var plugin; var $html; @@ -180,9 +180,11 @@ describe('Interchange', function() { // Trigger several window resize synchrnously and asynchronously. // --- - // Functions are nested to control when the check is made after the last resize - // more precisely (after 10ms). Timeout delays are most often not respected - // and the differences between several timeouts running in parrallel can be huge. + // Timeout delays are most often not respected and the differences between several + // timeouts running in parrallel can be huge. To prevent race conditions we: + // * nest timeout in order to make the delay between them more precise + // * run the test several time to wait for the debounce, which may be finally + // called way after the expected time. setTimeout(function () { let spy = sinon.spy(plugin, '_reflow'); $(window).trigger('resize'); @@ -192,12 +194,18 @@ describe('Interchange', function() { $(window).trigger('resize'); $(window).trigger('resize'); - setTimeout(function () { - sinon.assert.calledOnce(spy); + tryInterval({ + interval: debounce, + timeout: 1000, + try: () => { + sinon.assert.calledOnce(spy); + }, + then: () => { + $.triggersInitialized = false; + done(); + }, + }); - $.triggersInitialized = false; - done(); - }, debounce + 1); }); }); });