Hacker News new | past | comments | ask | show | jobs | submit login

I’ve been through a few “intro to react” courses like this now, and I have not come across a single one that talks about testing at any length, which seems insane to me. When I was learning Rails many years ago, test-driven development was all the rage.

React, with it’s declarative approach, stateless components, immutable state, etc. seems purpose-built for testability. TDD with React should be ridiculously easy, but I wouldn’t know, because no one seems to want to talk about it.




The culture doesn't exist in JavaScript land because historically it has been difficult to do. The tooling sucked. It is getting vastly better, but sadly, it will take effort to get back into the practice.

I hope that more people building the learning courses will focus on that. If I had time, I'd do one myself, as I now heavily test all my React stuff. I refuse to build another webapp without proper automated unit testing. It catches so much stuff.



No offense, but I feel like this is not a good example to follow.

The first examples are better off with just using snapshots. Even if the author is trying to explain the concepts, it is really poor to show bad examples that could be covered by a simpler solution. If I read that and didn't know about snapshots, I'd think to myself, "why am I testing strings?" and then skip testing entirely.

Mocking Axios also seems like the wrong way to approach things. I'd extract the networking code from the presentation code. Possibly by using mobx-state-tree (which is an epic solution to a hard problem). This way, I wouldn't even need to mock Axios at all and I could then just take advantage of snapshots again by providing actual mock data to my components directly.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: