DEV Community

Discussion on: What do you think of React Testing Library?

Collapse
 
2ezpz2plzme profile image
Steven Liao • Edited

:/ Ever since I learned about the RTL ideology, using Enzyme has just been pretty miserable for me. It's so ez to test an implementation detail, find elements that also return the Component element rather than just the DOM element.

At work, I mostly see shallow rendering, expecting this shallow wrapper to match snapshot, expecting wrapper.state('whatever') to equal something... Don't really wanna start any crap so I try not to say anything.

Also, I can't seem to find another reliable way in Enzyme to wait for an async componentDidMount besides returning the promise inside componentDidMount and awaiting. I don't really like this approach though... because it relies on implementation detail.

// something.tsx
componentDidMount() {
  return promise
}

// something.test.tsx
await wrapper.instance().componentDidMount()
wrapper.update()
expect(...)...

The frontend architect at my company endorses this pattern. So I'm pretty much forced to use this pattern since I can't use RTL waitForElement.

Btw, looking forward to your talk at useReactNYC on Tuesday.

Thread Thread
 
kentcdodds profile image
Kent C. Dodds

Sweet! Let me know who you are! Looking forward to meeting you.