小编Vau*_*ers的帖子

嵌套在redux形式的Field标签中时,无法模拟材料UI复选框上的酶测试点击

我正在尝试进行酶/摩卡/柴的测试,以模拟在materialUI Checkbox标记中将检查状态从true更改为false的情况,该标记包装在redux形式的Field中并由其呈现。我能够模拟对嵌套在Field标签内部的本机组件(复选框等)的点击,但是当嵌套时,无法模拟对材质UI标签的点击。我能够访问Checkbox标记上的其他属性,但是无法模拟事件。

UserForm.jsx   

renderCheckbox(props) {
  return (
   <Checkbox
      label={props.label}
      value={props.input.value}

// working code in the app:
      onChange={ event => {
      this.props.actions.toggleSuperAdmin(props.input.value)}}

// test code, not able to simulate even this click in Enzyme, 
// tried to break function down into simplest event I could think of, 
// and still not functioning in the test:               
      onCheck={() => console.log("onClick in UserForm.jsx")}

      {...props.input}
   />
  )
}
Run Code Online (Sandbox Code Playgroud)

在我的render函数内部,有这段代码调用了renderCheckbox

    UserForm.jsx  

    render() {
        return (
          <Paper zDepth={0} rounded={false}>
            <form id='user-form' onSubmit=
    {this.props.handleSubmit(this.handleUserSubmit.bind(this))}>
              <Field name='is_super_admin' 
                component={this.renderCheckbox} 
                label='Work …
Run Code Online (Sandbox Code Playgroud)

reactjs material-ui redux-form enzyme react-redux

2
推荐指数
1
解决办法
2619
查看次数

标签 统计

enzyme ×1

material-ui ×1

react-redux ×1

reactjs ×1

redux-form ×1