Most of my days are spent writing Ruby code (Rails/Sinatra). When using Ruby, writing tests before you write code has been basically an inseparable part of my professional life for years.
Writing tests for JS has always felt awkward to me if I’m honest. The tests run in a browser runner (mocha or whatever) and it’s not as flowing as writing Ruby tests.
If you read my post about my workflow My development workflow (vim+tmux+terminal+alfred) Awesomeness you can clearly see how it flows easier through the day. I just spend all of my day in the terminal, I never really even open the browser unless I need to see how something looks.
Current state of TDD in JS (outside looking in)
Yesterday I purchased Modern React with Redux course. I have to say I was kinda shocked.
I browsed through the course and I did not see a single test, there’s no lecture with the word “test” in the title.
The lecture flow is basically this:
- Write code
- Refresh browser (Well, this can obviously be hot-loaded, it’s not really the point).
- Check console for errors/typos
- Fix code
- goto 1
This is not the first time I encounter this “flow” and it always felt really weird to me, it feels slow and sluggish. Just by switching contexts to the browser every time feels out of flow.
This lead me to look deeper into the project.
When you work with Rails/Ruby you basically work a lot with gems so all the npm libraries you use in projects are comparable.
I was looking at the project at the center of the Redux lecture and started looking up some of the libraries it’s using like
redux-promise. I looked it up on Github it does have tests.
Even then, in rails, you still have tests for your code.
If you look at Rails Tutorial you can see how deeply rooted the testing “culture” is in the Ruby/rails world.
Is tooling the problem?
Huge part of my role is handling devops, writing chef recipes and cookbooks. With chef the test tooling is really awkward as well. You need to run vagrant, test kitchen, ssh into virtual machines and more.
If you look at open source recipes/cookbooks a lot of them don’t have tests as well. I found this to be kinda similar to what you have with JS.
What do you use?
Going back to what we do at Gogobot. we use
require.js in order to modularize the code and we definitely spec out logic and rendering.
The point of this post is not to slam anyone. Not that author of that course or any maintainer of libraries. It’s just stating how I feel about testing in the JS ecosystem.
Do you feel the same? You don’t? I would love to discuss in the comments.