2016-04-28 9 views
0

したがって、特定のページからすべてのタブを削除する機能があります。この関数で宣言された変数があります。この変数にダミーの値を渡して、値が渡され、関数が実行されるようにする必要があります。パラメータのない関数のTestUtilsテストケースへの書き込み

ReactJS TestUtilsを使用してテストケースを作成するにはどうすればよいですか?

_removeAllTabbing() { 
const accordionTitleAnchors = [ 
    document.getElementById('accordion-panel-1').firstChild, 
    document.getElementById('accordion-panel-2').firstChild, 
    document.getElementById('accordion-panel-3').firstChild, 
    document.getElementById('accordion-panel-4').firstChild, 
    document.getElementById('accordion-panel-5').firstChild 
]; 

_.each(accordionTitleAnchors, accordionTitleAnchor => { 
    this._removeTabbing(accordionTitleAnchor); 
}); 

}

これまでのところ、私はこの

xit('should call _removeAllTabbing function',() => { 
    const educate = new EducateAccordion(); 
    const accordionTitleAnchors = TestUtils.scryRenderedDOMComponentsWithClass(this.component, 'panel-title');; 

    educate._removeAllTabbing(accordionTitleAnchors); 
}); 

を持っている誰もが異なるフロントエンドのシナリオをテストするためのいくつかのドキュメント/記事を共有することができた場合にも、それは素晴らしいことでしょう。

答えて

0

したがって、renderIntoDocumentは機能しませんでした。ここでは?

が私のために動作するコードである理由:(だろう。

it('should validate _removeAllTabbing function',() => { 
     const educate = new EducateAccordion(); 
     const activeKey = 1; 

     const dummyElement = document.createElement('div'); 

     for (let i = 1; i <= 5; i++) { 
      const temp = document.createElement('div'); 

      temp.setAttribute('id', 'accordion-panel-' + i); 

      const temp2 = document.createElement('div'); 

      temp2.setAttribute('class', 'panel-title'); 
      temp2.setAttribute('role', 'tablist'); 

      temp.appendChild(temp2); 
      dummyElement.appendChild(temp); 
     } 

     document.body.appendChild(dummyElement); 

     educate._removeAllTabbing(); 

     this.accordionDummy = ReactDOM.findDOMNode(dummyElement); 

     this.accordionTitleAnchors = this.accordionDummy.getElementsByClassName('panel-title'); 

     _.each(this.accordionTitleAnchors, (item) => { 
      expect(item.getAttribute('tabIndex')).to.equal('-1'); 
     }); 
    }); 

アプリケーションのフロントエンドのテストナビゲーション部

する方法を把握する必要があり
関連する問題