1

入力フィールドの値を設定できません。私は何を間違っていますか?さらに情報が必要な場合は、その旨をお知らせください。ありがとうございました。

describe('SignUpComp', () => {
    let signUpComp, node;

    beforeEach(() => {
        signUpComp = TestUtils.renderIntoDocument(<SignUp />);
        node = ReactDOM.findDOMNode(signUpComp);
    });

    // First name
    it('it should trigger error `min chars` if input firstName is too short', () => {
        let elements = selectElements('firstName');

        TestUtils.Simulate.change(elements.input, { target: { value: 'abc' } });
        console.log(elements.input); // I can not see the change
        console.log(node); // I can not see the change

        expect(elements.error.textContent).to.equal(errorMsg.tooShort('First name', 2));
    });

    function selectElements(element) {
        let input = node.querySelector('#' + element);
        let error = node.querySelector('#' + element + '+ p');

        return { input, error };
    }
4

1 に答える 1

0

酵素を見ることをお勧めします。これにより、反応コンポーネントのテストが大幅に簡素化されます。

酵素を使用すると、次のことが簡単にできます。

const form = mount(<MyComponent />);
const input = form.find('input').get(0);
input.value = 'Blah blah';
于 2016-08-13T15:18:59.637 に答える