The state of Testing in Javascript (React Angular etc)

Intro

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.

Our stack at Gogobot includes a TON of javascript (require.js, Backbone, Angular, jQuery and more) so I am no stranger to JS and been writing a lot of it as well.

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:

  1. Write code
  2. Refresh browser (Well, this can obviously be hot-loaded, it’s not really the point).
  3. Check console for errors/typos
  4. Fix code
  5. 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.

Is the problems that Javascript testing is not streamlined enough? Is there not enough separation between the logic and the UI to allow real flow of test?

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.

What do you use in your company? How do you test your Javascript code?

Discussion

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.

Edit (01-08-2016)

patrickfatrick commented on Redit with a great looking resource Full-Stack Redux Tutorial.