Testing React Forms with Enzyme

Tyler Clark
InstructorTyler Clark

Share this video with your friends

Send Tweet

In this lesson we walk through four different sets of tests. We have a built out form that on submit, sends an ajax request with the inputed information. We walk through how we can test default options, simulate user input, actually submitting the form, and saving a snapshot of the form's layout.

TheProgram
TheProgram
~ 3 years ago

Great course first off! I am curious what is the difference between using the it() method to describe a test, or the test() method?

Stefan
Stefan
~ 3 years ago

There is a bug in updateInput(): It has to be target, not currentTarget. Correct version:

const updateInput = (wrapper, instance, newValue) => {
  const input = wrapper.find(instance)
  input.simulate('change', {
      target: {value: newValue}
  })
  return wrapper.find(instance)
}
Kenneth Marshall
Kenneth Marshall
~ 2 years ago

Why couldn't you just return input instead of finding the instance again?

const updateInput = (wrapper, instance, newValue) => {
  const input = wrapper.find(instance)
  input.simulate('change', {
      target: {value: newValue}
  })
  return input // <------- why not?
}