Hacker News new | ask | show | jobs
by FLGMwt 3158 days ago
That's surprising to me! My main complaints of Angular 2+ are around testing, but I've had nothing but love for React testing (enzyme, chai, karma)

EDIT: whoops, mistyped. We don't use karma anymore in our React testing stack. It's mocha now.

2 comments

My gripe with testing in React has a lot to do with testing in JS in general - it avoids the elephant in the room of how to mock dependencies (whether it be functions, classes, etc.), and control various scenarios so you appropriately unit test business logic. One can impose a solution by convention with React, whether it be creating/using a DI mechanism, creating functions that one can pass in dependencies to that returns the desired function, or other numerous ways. Or one can choose to avoid creating a solution and decide not to directly test those scenarios, but then that just leads to more expensive, fragile, and complicated scenarios where one loses the advantage of the fast & tight feedback cycle a unit test gives you.

Angular’s solution of a robust DI mechanism is a little on the heavy side, and the test execution perf is worse than Angular 1’s in general, but it is almost certainly the most powerful test helper situation available for testing frontend JS chrrently.

Note that testing serverside JS doesn’t suffer as much, since there are libraries for making use of the require cache for mocking such as testdouble.

Chai and karma aren't specific to react. I remember using them with angular 1.x back in the day.
Aye, I didn't mean to imply that, I was listing my React testing stack :)

Hah, looking now, I realize I mistyped. We use mocha, not karma. Was conflating things

I thought Karma was specific to Angular in fact!