2014-04-22 52 views
0

任何人都知道如何測試角動畫?使用$ animateProvider或angular.module('',[])。animate()創建的動畫?我正在構建一個動畫庫,這很好,但我找不到使用$ animate測試動畫的正確方法。他們從不工作。我已經破解它開始工作,但我幾乎重新創建每個測試中的所有動畫。爲了確保它不是我的動畫,我在測試中創建了一個新的動畫。我直接從Angular的源代碼中獲得了這一點,但它仍然不起作用。 測試動畫角1.2+

describe('Testing Async Animations', function() { 
    var am = false; 
    beforeEach(module('ngAnimate')); 
    beforeEach(module('ngAnimateMock')); 
    beforeEach(module(function($animateProvider){ 
    $animateProvider.register('.fade', function(){ 
     return { 
     enter: function(element, done){ 
      console.log('here'); 
      am = true; 
      done(); 
     } 
     }; 
    }); 
    })); 

    /* the done() method is something mocha provides. 
    to make this work in Jasmine, just follow their 
    example with using a asynchronous test */ 
    it("should asynchronously test the animation", function() { 
    inject(function($animate, $compile, $document, $rootScope, $rootElement) { 
     var element = $compile('<div class="fade">hello</div>')($rootScope); 
     $rootElement.append(element); 
     angular.element($document[0].body).append($rootElement); 
     $animate.enabled(true); 
     $animate.enter(element, $rootElement); 
     $rootScope.$digest(); 
     expect(am).to.be(true); 

    }); 
    }); 

}); 
+0

「他們從不工作」。測試還是動畫?他們不工作的方式?你能舉一個你測試過的示例動畫嗎? Plunker在這裏會很有幫助。此外,你複製了Angular的測試,並提到你在測試中重新創建動畫的事實,表明你可能正在測試錯誤的東西。 Angular的測試檢查它的API(例如'enter'函數)在什麼時候運行。你的測試應該驗證'enter'函數內發生的行爲。再次,在這裏和在Plunker發佈動畫代碼將會很有幫助。 –

回答

0

我是在我測試動畫的方式是正確的,但當時的角度進行了更改在v1.2.16 ngMocks其中搞砸一切。