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

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

    None of the above worked for me. This is what worked for me on Enzyme ^3.1.1:

    input.instance().props.onChange(({ target: { value: '19:00' } }));
    

    Here is the rest of the code for context:

    const fakeHandleChangeValues = jest.fn();
      const fakeErrors = {
        errors: [{
          timePeriod: opHoursData[0].timePeriod,
          values: [{
            errorIndex: 2,
            errorTime: '19:00',
          }],
        }],
        state: true,
      };
    const wrapper = mount();
    const input = wrapper.find('#input-2').at(0);
    input.instance().props.onChange(({ target: { value: '19:00' } }));
    expect(wrapper.state().error).toEqual(fakeErrors);
    

提交回复
热议问题