0

私は誰かからプロジェクトを引き継いでおり、それは React で構築されています。ボタンのクリックがシミュレートされた後に関数が呼び出されないため、テストの 1 つが失敗しています。ブラウザでアプリを使用すると、関数が呼び出されるので、何が起こっているのかわかりません。私は React を始めたばかりで、これまでテストを書いたことがないので、見落としている非常に明白なものがあるかもしれません。

This is the test:
it('Clicks save entry without meeting validation', function() {
        expect(WorkHistoryItemContainer.state.saving).toBe(undefined);
        expect(WorkHistoryItemContainer.state.errors.length).toBe(0);

        var organisation = React.findDOMNode(WorkHistoryItemContainer).querySelector('input[name=organisation]'),
            role = React.findDOMNode(WorkHistoryItemContainer).querySelector('input[name=role]'),
            date = React.findDOMNode(WorkHistoryItemContainer).querySelector('input[name=period]'),
            duration = React.findDOMNode(WorkHistoryItemContainer).querySelector('input[name=duration]');

        organisation.value = mockValues.organisation;
        role.value = mockValues.role;
        date.value = mockValues.organisation;
        duration.value = mockValues.duration;

        console.log('----------------');
        console.log(organisation.value);

        ReactTestUtils.Simulate.change(organisation);
        ReactTestUtils.Simulate.change(role);
        ReactTestUtils.Simulate.change(date);
        ReactTestUtils.Simulate.change(duration);

        ReactTestUtils.Simulate.blur(organisation);
        ReactTestUtils.Simulate.blur(role);
        ReactTestUtils.Simulate.blur(date);
        ReactTestUtils.Simulate.blur(duration);

        console.log('----------------');
        console.log(organisation.value);

        var SaveButton = React.findDOMNode(WorkHistoryItemContainer).querySelectorAll('.Form-link')[1];
        expect(SaveButton.innerText).toBe('Save');

        console.log('----------------');
        console.log(SaveButton);

        ReactTestUtils.Simulate.click(SaveButton);

        // THIS LINE FAILS:
        expect(WorkHistoryItemContainer.handleSave).toHaveBeenCalled();

        expect(WorkHistoryItemContainer.state.saving).toBe(true);

        expect(spyFunc.handleSave).toHaveBeenCalled();
    });

これは、関連する場合の handleSave 関数です。

handleSave: function (ev, eventAttrs) {

        var isNew = this.state.id === '';

        this.setState({
            editing: false,
            saving: true
        });

        this.props.saveEntry(ev, eventAttrs, this);
    },

コンソールに表示されるエラーは次のとおりです。

PhantomJS 1.9.8 (Linux) Rendering a new work history item Clicks save entry without meeting validation FAILED
    Expected spy handleSave to have been called.
        at /tmp/d89697d9775596afa26fe8390227c689.browserify:3044
    Expected undefined to be true.
        at /tmp/d89697d9775596afa26fe8390227c689.browserify:3049
    Expected spy handleSave to have been called.
        at /tmp/d89697d9775596afa26fe8390227c689.browserify:3051

何か案は?どこから始めればよいのかよくわかりません...コンソールにいくつかのものを記録しましたが、問題ないようです(つまり、ボタンなどがあります)。

4

0 に答える 0