0

したがって、特定のページからすべてのタブを削除する機能があります。この関数には、作業を行う変数が宣言されています。値が渡されて関数が実行されるように、この変数にダミー値を渡す必要があります。

以下の 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);
});

また、さまざまなフロント エンド シナリオをテストするためのドキュメントや記事を誰かが共有できれば、すばらしいことです。

4

1 に答える 1

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');
        });
    });

アプリケーション フロントエンドのナビゲーション部分をテストする方法を理解する必要がある

于 2016-05-03T06:38:14.683 に答える