- Initialized git?
- Initialized npm?
- Install your packages with the command
npm install -D mocha chai
- Flags:
- use
-D
to save the package(s) in thepackage.json
file under"devDependencies"
- use
-S
to save the package(s) in thepackage.json
file under"dependencies"
- use
- Flags:
Packages for running, creating, and managing your tests are generally considered development dependencies. Use the -D
flag.
- Mocha, by default, looks for test files in a directory called
test
.- create your test files in this directory. here is a suggestion for file name:
*.spec.js
* refers to the filename you're testing. If you're testing a module saved ascalculator.js
your test file should be namedcalculator.spec.js
- create your test files in this directory. here is a suggestion for file name:
- Did you require
mocha
and/orchai
? - Initialize chai's
expect
orshould
? - Are you requiring the
file
you're testing? ex.calculator.spec.js
tests thecalculator.js
file.calculator.js
needs to be imported into thecalculator.spec.js
file using node'srequire
function. desc
block? reference at mochajs.orgit
block? refernece at mochajs.org- assertions? reference at chaijs.com
- command:
mocha
- keep watching:
mocha --watch
- bail on first failure:
mocha --bail
- all-in-one:
mocha --watch --bail
aw yiss.