DEV Community


Discussion on: Don't use getByTestId 🐙

jackmellis profile image
Jack • Edited

Really great article. I've been a testing advocate for a long time and only really recently started to rethink my white box approach. My only issue is there is a clear distinction between proper unit tests that should be white boxes, and component testing which are really more like integration tests. If I fundamentally changed my code and my unit tests all passed I'd be concerned that my tests were wrong!

jacques_blom profile image
Jacques Blom Author

Thanks, Jack! 🙌

Definitely agree with that. The approach I've taken with my tests is to mostly write integration tests for my UIs. I like that you're testing the way the user experiences the app. If a test that tests a user's experience breaks (if it's not a false positive), you know a real user is likely going to experience that issue.

I definitely see the value in unit tests, though. I write a bunch of tests for individual functions and hooks in my code that are important to the app functioning, and where that function's behavior isn't easy to test with an integration test. Of course, the downside here is that you're testing implementation details and your code changing will break your tests - but that's kind of the point like you said. 😊