Chapter 4: Testing JavaScript
Activity 4 – Utilizing Test Environments
You have been tasked with upgrading your Fibonacci sequence test code to use the Mocha test framework. Take the Fibonacci sequence code and test code you created for Activity 1 and upgrade it to use the Mocha test framework to test the code. You should write tests for the n=0 condition, then implement the n=0 condition, then write tests for and implement the n=1 condition, then write tests for and implement the n=2 condition, and finally do so for the n=5, n=7, and n=9 conditions. If the it()
test passes, call the done
callback with no argument. Otherwise, call the test done
callback with an error or other truthy value.
To utilize the Mocha test framework to write and run tests, follow these steps:
- Set up the project directory with
npm run init.
Install mocha globally withnpm install mocha -s -g
. - Create
index.js
to hold the code andtest.js
to hold the tests. - Add the test script to...