0

cleanup doesn't work in codesandbox and I comment the ReactDOM.render function as someone suggesting to in here: https://github.com/CompuIves/codesandbox-client/issues/1525 and it works, but fireEvent doesn't work. Vice versa, when I don't comment the ReactDOM.render function, fireEvent works and cleanup doesn't.

code: https://codesandbox.io/s/mqm2w49y1x

berlirmp
  • 1
  • 2
  • I personally use enzyme for testing events https://airbnb.io/enzyme/docs/api/ReactWrapper/simulate.html - I know the question is about react-testing-library, but I trully recomend it. – Zydnar Apr 06 '19 at 18:18
  • I would check first if getByText returns what you want - you can console.log this. I'm not sure but it looks like `` don't have onClick function at all, so nothing happens. – Zydnar Apr 06 '19 at 18:23
  • @Zydnar I don't know why is that happening, but if we uncomment the ReactDOM.render function, the fireEvent get triggered – berlirmp Apr 06 '19 at 18:36
  • Maybe as workaround create separate test, where you don't import ReactDOM? – Zydnar Apr 06 '19 at 18:38
  • Possible duplicate of [Issue with React-Testing-Library in codesandbox.io](https://stackoverflow.com/questions/55387122/issue-with-react-testing-library-in-codesandbox-io) – Gio Polvara Apr 07 '19 at 09:20
  • fireEvent seems to work for me without `ReactDOM.render`. https://codesandbox.io/embed/o93q230lz9 – 10101010 Apr 08 '19 at 09:34

1 Answers1

0

RTL doesn't work well in codesandbox. Run your tests in your local machine instead.

Gio Polvara
  • 23,416
  • 10
  • 66
  • 62