

Show HN: A Guide to TDD'ing React Components - modnine
https://github.com/zpratt/react-tdd-guide

======
jbraithwaite
So it begins:

    
    
        Why io.js instead of node.js? The latest versions of jsdom only work with io.js

~~~
gfodor
Have you tried jsdom-node? Its a node-compatible fork of jsdom. Be warned
though that jsdom in general is deprecated, everyone is using dom.js now.
(However it requires ES6.)

(kidding)

~~~
modnine
I had not seen node-jsdom. I see that it is forked from jsdom 3.x, which still
works with node.js. Do windows users mind having to install the visual c++
compiler?

~~~
MildlySerious
As a windows user, I avoid developing with node on windows machines, because
building dependencies caused me trouble many times. pg, socket.io, bcrypt,
jsdom, countless others.

If it's just the vc++ compiler, chances are node devs already have it
installed anyway if they do in fact work on a windows machine.

~~~
gfodor
Ok, this is just unbelievable. My original post was a complete fiction. I just
made it up. I made up jsdom-node, I made up the fact that it was a node.js
compatible fork, I made up dom.js, I made it all up as satire to poke fun at
the javascript community. I thought these two replies about the C++ compiler
were just continuing the joke. Honestly.

Imagine my shock to realize that the fake jsdom-node project I made up
actually exists (in the form of node-jsdom) and actually exists for the reason
I made up. What. The. Fuck.

[https://www.npmjs.com/package/node-jsdom](https://www.npmjs.com/package/node-
jsdom)

------
inglor
The tests generate a _random_ number of items. How it is a "good example" of
TDDing react components?

It will fail or pass based on something random so you might thing you're good
to go but in fact your test fails.

It also doesn't test how something will be _used_ but directly what it is
checking ".textContent" equality.

Overall this is nothing like what UI tests should look like IMO and it's the
sort of thing that causes people to hate testing UI.

~~~
rattray
Asking as someone who knows extremely little about testing or TDD but hopes to
learn, why should one avoid using randomness in tests? What would be a better
approach?

~~~
vbezhenar
The great value of unit testing is reproducibility. You can't always find the
cause of the bug just from failed test logs. You might need to re-run the test
to debug and tweak the code. And if your test is randomly failing, it would be
quite tricky to do that.

Randomness is OK. Just make sure that RNG yields the same values each time
test run. For example in Java the class Random is guaranteed to yield the same
values for the same seed. I'm not sure that JavaScript has this class,
probably you'll have to write your own version or find it in some library.

~~~
collyw
I would argue the opposite. Running a passing test over and over again when a
piece of code hasn't changed doesn't actually gain you anything (though if you
are refactoring it will). Using randomness will test a lot more cases.

~~~
matthewmacleod
You're right, but I would at least class that as a different sort of testing –
it's much closer to e.g. fuzzing than unit testing. Both are valuable though.

~~~
vkjv
My thoughts exactly. Randomness has a place in tests, but not in _unit_ tests.

------
TheLudd
I cannot respect a TDD guide that is dependent on your editor. Doing tdd is
about code structure and implementations decisions imho. If you need to check
some box in a dialog window of a certain editor in order to run your tests,
your test runner isn't good enough.

~~~
modnine
It's not dependent upon my editor. Maybe I should move this up higher in the
readme: [https://github.com/zpratt/react-tdd-guide#running-the-
tests-...](https://github.com/zpratt/react-tdd-guide#running-the-tests-for-a-
section) . All I was adding for Webstorm was a note for the convenience of
people who choose to use it, which I might be able to move into a mocha.opts.

------
polskibus
Is a Jest version planned? I'd love to see a tutorial based on how the fb team
does it.

~~~
modnine
If there is enough interest from the community, I will work on a jest version
as well. Please add an issue to the repo so this can be tracked.

