I wrote these tests as part of the Watch and Code Javascript course.
To test forEach()
and filter()
methods I have used tinytest.js, that from the map()
tests has been renamed simpletest.js because of some minor edits suggested during the course by Gordon Zhu:
- Success tests should be green
- Fix the total number of failures (in tinytest.js it's double the right number)
- Once point 2 is fixed, failure tests should be red
- Only show stack traces if you click the 'expand' arrow button
- Output summary statistics to the DOM
and some of my own:
- Wait for the DOM to be ready before executing javascript by putting javascript code before the closing
body
tag, instead of usingsetTimeout()
, which looks to me more complex than necessary - Set the
body
background style property with a call to a helper method, instead of doing it directly into therunTests()
method - Delete the global variables binding to the
TinyTest
object (in my caseSimpleTest
), because I don't see its usefulness - Delete some global variable:
assert()
, becasue I don't use itassertEquals()
, becasue I always use the strict formtests()
, because when I call the main method of theSimpleTest
object, I'd like to use the dot notation for clarity:SimpleTest.runTest()
- Make the
eq()
alias point toassertStrictEqual()
-
Write the name of the test (which is a property of the object I pass to
runTests()
). -
Make the test fail.
-
Make it pass by writing the application code necessary to make it pass.
In general:
- Tests: go from simple to complex
- Try to write as little code as possible to make the test pass, 1 error message at the time