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

后端 未结 16 2028
面向向阳花
面向向阳花 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:30

    I solved in a very simple way:

    1. Set the value from props:
      const wrapper: ShallowWrapper = shallow();
    
    1. Html code:
      
    
    1. Access the attribute from wrapper.find(element).props().attribute-name:
      it('should render user name', () => {
        expect(wrapper.find('.edituser-name').props().defaultValue).toContain(props.name);
      });
    

    Cheers

提交回复
热议问题