Download the latest version of mochajs from here, chaijs from here and sinonjs from here. Save them as mocha.js, chai.js and sinon.js respectively.

Also download the css used by mocha from here and save it as mocha.css

You might also refer to these files from a CDN like https://cdnjs.com/ as used below

Now create a car-test.js file that will hold the unit tests for our Car object.

Since we are running these tests from our browser to start with, we will create a unitTests.html file.

This file should include links to the different libraries and test files that we have created as shown below.

<head> <meta charset="UTF-8"> <link href="mocha.css" rel="stylesheet" /> </head> <body> <!-- mocha needs this div to run --> <div id="mocha"></div> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.min.js"></script> <script src="car.js"></script> <script src="http://cdnjs.cloudflare.com/ajax/libs/mocha/2.3.4/mocha.min.js"></script> <script src="http://cdnjs.cloudflare.com/ajax/libs/chai/3.4.1/chai.min.js"></script> <script src="http://cdnjs.cloudflare.com/ajax/libs/sinon.js/1.15.4/sinon.min.js"></script> <script src="car-test.js" defer></script> <title>Mocha Unit Tests</title> <script> // Use mocha in Behaviour-Driven Development setup mocha.setup('bdd'); // set chai.expect to window for easy access

window.expect = chai.expect; window.onload = function() {

// Have mocha run all tests when page loads

mocha.run(); } </script> </body>

Notice above that we have set expect method to window, to make it easily accessible

Note If you run mocha from command line (not covered here) it looks for test in this directory:

./tests/*.js

So you may want to put your test in tests folder and reference it appropriately in corresponding html file.