d3js unit testing removal of elements

前端 未结 1 560
囚心锁ツ
囚心锁ツ 2021-01-23 13:10

I am using jasmine to unit test some interactions in a d3.js chart. I have been using d3.timerFlush() to complete the executions of anima

1条回答
  •  时光取名叫无心
    2021-01-23 13:38

    Alright, figured it out, d3 version 3 used to use date.now to measure time. Version 4 moved to performance.now.

    So, the correct code should be:

    it('it will remove all of the pie related elements from the DOM', () => {
        chartSvc.exit();
        performance.now = function() { return Infinity; };
        d3.timerFlush();
        let elements = svg.querySelectorAll(/* selects my elements */);
        expect(elements.length).toEqual(0);
    });
    

    Here's some test code:

    
    
    
      
        
        
      
    
      
        
          
            
            
            
            
          
        
        
      
    
    

    0 讨论(0)
提交回复
热议问题