简体   繁体   English

检查onChange是否与setState一起正常工作

[英]Check if onChange works correctly with setState

Trying to test if ParameterLabel value changed when onChange event was tested. 尝试测试在测试onChange事件时ParameterLabel值是否更改。 Something is missing on this line: 这一行缺少一些东西:

expect(wrapper.state('ParameterLabel'))).toEqual("ParameterLabel value"); expect(wrapper.state('ParameterLabel')))。toEqual(“ParameterLabel value”); //?? //?

I need to add context somewhere after wrapper.state, so it can check the value inside of ParamenterLabel and perform the change Using Shallow - Jest / enzyme 我需要在wrapper.state之后的某处添加上下文,因此它可以检查ParamenterLabel内部的值并执行更改Using Shallow - Jest / enzyme

it('Testing ParameterLabel onBlur event ', () => {
 baseProps.onBlur.mockClear();
 wrapper.setState({
    context:{
      ParameterLabel:'test',
      PARAMETER_TYPE: {
          ParameterTypeId:'ParameterLabel-Test'
        },
      PARAMETER_DATATYPE:{
          DataTypeId:'test'
        },
     },
  });
  wrapper.update() 
  wrapper.find('input[id="ParameterLabel"]').simulate('blur',{
    target: { 
       value:'ParameterLabel value', 
       id: 'ParameterLabel'
     }
 });
   expect(wrapper.state('ParameterLabel'))).toEqual("ParameterLabel value"); //??
});


<input id='ParameterLabel' className='user-value-field' onBlur={this.updateContext} defaultValue={this.state.context.ParameterLabel}

From your setState call, it looks like the state property 'ParameterLabel' is nested inside of 'context'. 从你的setState调用看起来,状态属性'ParameterLabel'嵌套在'context'中。

Try searching for the 'context' object inside your assertion then pulling out that property. 尝试在断言中搜索“context”对象,然后拉出该属性。 Something like: 就像是:

expect(wrapper.state('context').ParameterLabel)).toEqual("ParameterLabel value");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM