This site lists the protips that we shared with students during our courses
I’ve been tipping a few mobs of this thing, but I wanted to document it here as well.
When we are doing such rapid code-test-code-test-code-loops it can be come very cumbersome to
.skip
them - see above) andNormally we should have only one failing test at the same time which will help us to focus and divide the problem at hand into smaller chunks.
One way to do that is to use another reporter for our test runner, mocha. Open package.json
and find the scripts
node. Here’s how the test
script looks now:
"test": "node ./node_modules/.bin/mocha --reporter spec --exit \"server/**/*.spec.js\" \"client/**/*.spec.js\"",
See that part that says --reporter spec
, change it to --reporter dot
and then rerun the tests.
The output in the terminal will now look something like this:
․․․․․․․․․․․․․․․․․․!!!!!!,,,,,․․․․․․
24 passing (136ms)
5 pending
10 failing
(You might have to scroll up if you have many failing test. Psst… Don’t - use .skip
to get one failing test at the time).
Here’s how to read that:
.
!
,
This will help you to get a much tighter and readable feedback, minimizing scrolling through text and take the load of your brains of all the failing tests that you don’t need to care about.
There are a number of other reporters that could be useful. My two favorites are:
list
- creates sentences of the test descriptionmin
- clears the terminal putting the test output at the top of the screen. Very readableYou can see (and play with!) all the mocha reporters by going npx mocha --reporters
in the root of your project.