Disabling all D3 animations (for testing)

前端 未结 4 1504
旧巷少年郎
旧巷少年郎 2020-12-30 00:36

I\'m looking for a D3 equivalent to jQuery.fx.off = true.

Say you are writing tests (with Mocha, QUnit, etc.) for an app that uses D3. The app has some D3 animations

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-30 00:54

    An alternative to mocking out transitions is executing them synchronously directly to their final state.

    With D3.js v4, use:

    function flushAllD3Transitions() {
        var now = performance.now;
        performance.now = function() { return Infinity; };
        d3.timerFlush();
        performance.now = now;
     }
    

    With D3.js v3 and previous, do:

    function flushAllD3Transitions() {
        var now = Date.now;
        Date.now = function() { return Infinity; };
        d3.timer.flush();
        Date.now = now;
     }
    

    See also d3 issue 1789.

提交回复
热议问题