Regarding Quality Assurance: Testing with Chai

Hello, i just ran thru the Testing with Chai curriculum and had some hard time figuring out where certain stuff came from. After completing the challenges i start a revise and realized the suite function which is heavily relied on in the example repl is defined nowhere. After some search i found out its part of the Mocha engine, which was not even defined/imported in the file and i dont recall anywhere in the curriculum or in the previous basic Node exercises this package being discussed. It has been mentioned on very few occasions in the Chai curriculum, but out of context, or without a background, if i can call it that way.
What im trying to say and suggest is, there should be a quick introduction to Mocha, what it is and the User be told that its used alongside Chai for the current curriculum, or the code looks very confusing and doesnt make complete sense.

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.

1 Like

yes, i found a video on fcc youtube regarding mocha and things made much more sense. For example that it comes as a global object and there is no need to require it. Ive looked both Mocha and Chai documentations for more explanation once ive finished the curriculum, but i couldnt easily find more info on what i found confusing at first, altho now things make much more sense.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.