0

Hi guys I have a question for anybody that can help. Is there any helper function to translate a document.body to React structure and access it like getElementBy.. ? So I can access the individual components by React Names not by classNames or TagNames?

Code sample for the already implementation is shown below :

it("something, changes something", () => {
  const longFormatWithTimeCalendar = mount(<SingleCalendar {...longFormatWithTimeProps}/>)
  longFormatWithTimeCalendar.find("input").first().simulate("click")
  const timepickersHourInput = document.body.getElementsByTagName("input")[0]
  timepickersHourInput.value = "11"
  ReactTestUtils.Simulate.change(timepickersHourInput)
  expect(longFormatWithTimeCalendar.find("input").first().props().value).toBe("25 Dec 2017 11:00")
  longFormatWithTimeCalendar.unmount()
})

I use the document.body.getEmentsByTagName because this component is rendered outside the mounted component.

doelleri
  • 19,232
  • 5
  • 61
  • 65
Nikolaos
  • 1
  • 2
  • The enzyme wrapper .find function can find react components by their React names and you can use .instance combined with ReactDOM.findDomNode to get all the others. – Dakota Dec 01 '17 at 15:54
  • Possible duplicate of [how to check the actual DOM node using react enzyme](https://stackoverflow.com/questions/37723238/how-to-check-the-actual-dom-node-using-react-enzyme) – Dakota Dec 01 '17 at 15:56

0 Answers0