mocha-annotated
Mocha but with tasks and feedback built into it!
Install
npm install mocha-annotated
Use
mocha --reporter mocha-annotated/spec --ui mocha-annotated/ui 'src/**/*.spec.js'
Note: Use the --bail
flag so that you see at most one feedback message per test run.
UI
The Mocha ui is mocha-annotated/ui
and you can add it to your mocha
options using:
--ui mocha-annotated/ui
Reporters
Annotated spec reporter
--reporter mocha-annotated/spec
Annotated json reporter
--reporter mocha-annotated/json
Annotated json-stream reporter
--reporter mocha-annotated/json-stream
Profit
Use it.annotated(title, taskNumber, feedback, fn)
in place of it(title, fn)
to associate a task number and
some descriptive feedback (preferably in markdown) with each test case.
Use strip_heredoc
to format multi-line string templates by stripping leading whitespace, preserving newlines, and
preserving indentation level. You do not need to import strip_heredoc
, it is a part of the mocha-annotated UI.
For bonus fun, try using it.annotated.only()
, xit.annotated()
, and/or it.annotated.skip()
just like you
would with the normal it()
blocks in your testing code!
; ;
At the end of your test output, you will see the feedback for any failing test(s):
Using the mocha-annotated/spec
reporter
1) Task 1: put a boop in the beep Whoops, we forgot to put a boop in our beep when `fiddlesticks` is _truthy_. ```typescript
Using the mocha-annotated/json
reporter
Using the mocha-annotated/json-stream
reporter
Alternative Forms
While it.annotated(title, taskNumber, feedback, fn)
works when a task number is known and the feedback is predetermined, there are alternative forms to support other situations:
- Use
it.annotated(title, feedback, fn)
when there is no task number associated with the test. - Use
it.annotated(title, taskNumber, fn)
when there is no feedback associated with the test, or when feedback is included in a test assertion. - Use
it.annotated(title, fn)
when there is no task number associated with the test and feedback is undefined or dynamic (as above).
Following is an example of the dynamic feedback situation:
; ;
Annotated tests without predetermined feedback will also use messages from errors thrown within the test.