dojo / core

:rocket: Dojo 2 - language helpers and utilities.
http://dojo.io
Other
213 stars 58 forks source link

`utils#throttle()` test fails in Edge #357

Closed bryanforbes closed 7 years ago

bryanforbes commented 7 years ago

Bug

When running the unit tests on Edge, the following error is raised:

× MicrosoftEdge on windows 10 - utility functions - throttle - throttles callback (0.011s)
    AssertionError: Function should not be called until throttle delay has elapsed: expected 7 to be above 23
      at r  <node_modules/intern/browser/remote.js:69:491>
      at n.prototype.assert  <node_modules/intern/browser/remote.js:445:1237>
      at c  <node_modules/intern/browser/remote.js:458:2068>
      at s  <node_modules/intern/browser/remote.js:352:123>
      at o.isAbove  <node_modules/intern/browser/remote.js:476:1019>
      at Anonymous function  <tests/unit/util.ts:159:4>
      at Anonymous function  <node_modules/intern/browser/remote.js:104:780>
      at Anonymous function  <src/util.ts:64:2>
      at run  <tests/unit/util.ts:175:4>

Package Version: master

edhager commented 7 years ago

The setTimeout function on Edge doesn't seem to guarantee the delay. Load the page below in Edge and you will see the timer fire before the requested delay. This breaks the utils#throttle function.

<!DOCTYPE html>
<html>
<body>
<script>
    var counter = 0;
    var start = Date.now();
    console.log('Start ', start);
    var fn = function () {
        var end = Date.now();
        var diff = end - start;
        console.log('End ', end, diff, (diff < 25) ? '<<<<<<<<<<': '');
        counter++;
        if (counter < 15) {
            start = Date.now();
            setTimeout(fn, 25);
        }
    };
    setTimeout(fn, 25);
</script>
</body>
</html>