Best course for TDD in JavaScript

Hey,

I just bombed a technical interview because I don’t use TDD. I’ve been meaning to learn but never taken the time until now. I’ve tried to follow documentation for Mocha and a Youtube tutorial from Traversy but I’m having a hard time thinking of tests before writing the actual function.

Does anyone know of a course that they found helpful in understanding TDD?

Best regards,
Dan

Not sure I’m the right person to give you this info, but anyway.

Fun Fun Function, has a Unit testing in Javascript playlist you can check out

I haven’t really watched many of the videos (some are free some are not) but this site does a bunch of TDD. Again, I don’t have much personal experience with the site.
http://www.letscodejavascript.com

This is slightly contentious, because there are different ways of approaching testing, and in some (many?) cases TDD doesn’t work well (building UIs is often one case). TDD is also imo difficult if you don’t understand the problem that you are solving very well to start off with, as it is difficult to the write tests. It’s also quasi-religious, make of that as you will.

For JS specifically, make sure you know how to use and run the testing framework (you mention Mocha; Jest is another big one, and comes batteries-included. And Tape is very good by virtue of its simplicity). Once you’ve got that down pat, it’s more a case of concept rather than anything JS-specific. You need to understand how the program you’re trying to write/test works from a JS perspective, but most TDD concepts are language-agnostic.

There are several very good books. Note that none of these use JS as the teaching language, but that should not matter a huge amount because they are designed to explain how to think about writing good tests for programs in general. They are not free but I’m sure you can hunt around for them:

Test-Driven Development By Example by Kent Beck
The Art of unit testing by Roy Osherove
xUnit Test Patterns by Gerard Mezaros

These are just generally about writing software, and are both imo important books:

Code Complete
The Pragmatic Programmer

Here’s a list of TDD resources

The programming site Exercism is based on working through a set of katas (small self-contained problems, like FCC’s algorithm challenges) using TDD.

Another list: awesome-tdd

2 Likes

Ah, autocomplete :face_with_symbols_over_mouth:.

Thank you!

Thanks for the links. I will check that out on my lunch break.

Thanks for the book referrals. I read Uncle Bob’s books in college but I haven’t read anything by Kent Beck yet. I suppose it’s about time.

1 Like

I forgot about Kent Dodds, I know he does a lot on testing. Here is the testingjavascript site (kind of pricey) and here is his YouTube channel. This info might already be in one of the list posted.

What I would say is just start doing it all the time: it will be hard at first, but you’ll get used to it quite quickly – aim to get it down to being a habit. And with TDD in particular, there is a fairly consistent path to getting going, questions you can ask at first: does the thing you are testing exist? If it exists, what should it take as input? What should happen if the wrong input is put in? What should it produce as output? Start that last part by literally hardcoding the output, and then build more tests from there. And so on and so on. As I say takes practice, but many of the test cases naturally start to suggest themselves to you.

All you’re doing is putting things in place that let you be confident that the code works the way you want it to work, and that if something goes wrong there are a known set of things that can happen

1 Like