Test is not read me eventpreventDefault

I am trying to run test to pass current task and the test is not picking up my event.preventDefault in my handleSubmit method

Here is my handleSubmit method
**
handleSubmit =(event)=> {

// Change code below this line



this.setState({

  submit: this.state.input

})

event.preventDefault()



// Change code above this line

}
**


class MyForm extends React.Component {
constructor(props) {
  super(props);
  this.state = {
    input: '',
    submit: ''
  };
  // this.handleChange = this.handleChange.bind(this);
  // this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange =(event)=> {
  this.setState({
    input: event.target.value
  });
}

handleSubmit =(event)=> {
  // Change code below this line
  
  this.setState({
    submit: this.state.input
  })

  event.preventDefault()
  
  // Change code above this line
}


render() {
  return (
    <div>
      <form onSubmit={this.handleSubmit}>
        {/* Change code below this line */}
        <input type='text' value={this.state.input} onChange={this.handleChange}/>
        {/* Change code above this line */}
        <button type='submit'>Submit!</button>
      </form>
      {/* Change code below this line */}
        <h1>{this.state.submit}</h1>
      {/* Change code above this line */}
    </div>
  );
}
}
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36

Challenge: Create a Controlled Form

Link to the challenge:

It’s because of the arrow function. The test is using MyForm.prototype but the arrow function is not on the prototype. I will report it.

1 Like

I changed it to vanilla syntax where you had to bind in constructor and it took it. I thought it was strange it didn’t take es6 syntax(arrow). Thank you for making sure I wasn’t crazy, lol

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.