DEV Community

Discussion on: JavaScript Clean Code — Test-Driven Development

Collapse
 
gypsydave5 profile image
David Wickes • Edited

We only write a test that fails and not makes compilation fail.

It's okay to write a test that makes compilation fail. Compilation can be thought of as the first 'test' your test makes you pass.

This way you can write a test that involves functions, interfaces, modules etc that don't yet exist in the code.

The test should be an act of "wishful thinking" - you want to imagine the way you want your code to look and act, then make it happen.


Also important: only write one test at a time - don't write lots of tests up front and spend all your time trying to pass them. One test, make it pass, tidy up, next test.

Collapse
 
aumayeung profile image
John Au-Yeung

I think that makes sense.

No matter what test you have it will fail since the code isn't implemented yet.

Once the code is done then it should compile and pass the test.