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

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

    Got it. (updated/improved version)

      it('cancels changes when user presses esc', done => {
        const wrapper = mount();
        const input = wrapper.find('input');
    
        input.simulate('focus');
        input.simulate('change', { target: { value: 'Changed' } });
        input.simulate('keyDown', {
          which: 27,
          target: {
            blur() {
              // Needed since  calls target.blur()
              input.simulate('blur');
            },
          },
        });
        expect(input.get(0).value).to.equal('Hello');
    
        done();
      });
    

提交回复
热议问题