Enzyme - How to access and set <input> value?

后端 未结 16 2152
面向向阳花
面向向阳花 2020-12-07 22:06

I\'m confused about how to access value when using mount. Here\'s what I\'ve got as my test:

  it(\'cancels changes w         


        
16条回答
  •  北荒
    北荒 (楼主)
    2020-12-07 22:07

    In my case i was using ref callbacks,

       this._validateMail()}
                                                           ref={(val) =>{ this._username = val}}
                                                        >
    

    To obtain the value. So enzyme will not change the value of this._username.

    So i had to:

    login.node._username.value = "mario@com.com";
        user.simulate('change');
        expect(login.state('mailValid')).toBe(true);
    

    To be able to set the value then call change . And then assert.

提交回复
热议问题