It’s confusing at first. Mocha is the test runner; it just executes whatever tests you define and provides you with some functions, like suite()
to group tests meaningfully and to setup and teardown data and conditions to make those groups of tests work. Most of the projects use the TDD interface to mocha, so look for that documentation as opposed to the BDD interface documentation that seems more popular now.
Chai and it’s helpers provide different styles of assertions and other helpers to help construct your tests. So, you’ll use calls to chai functions to help write the tests inside of calls to mocha functions to help you run your tests.
If you poke around in the project boilerplate (try test-runner.js
), you can see a lot of how mocha is used, but it’s not really important to understand it in the projects where it’s already included in the boilerplate. You’ll get more familiar with it as you do the projects, and once you are doing the ISP projects, you’ll learn plenty about mocha. Mocha’s documentation is fairly good too, so it’s easy to learn on your own.
It’s also worth noting that while mocha/chai are popular, they are not the only runner/assertion suites used in JS. You’re likely to encounter others along the way.
But you’re right, it’s a lot and it’s a surprise when you first see it. I just blackboxed it wrote the tests first and later I looked in to what mocha was doing.