Test my bootcamp
Write unit tests for the list of functions below you wrote in the bootcamp.
Create a folder in your
projectsfolder calledbootcamp-terminal-tests. Write all your tests in a sub-folder calledtestin there. Commit it to github using a repository calledbootcamp-terminal-tests.
Write tests for:
- greet
- isFromBellville
- regCheck
- countRegNumber
- isWeekday
- yearsAgo
- countAllPaarl
- countAllFromTown
- transportFee
- totalPhoneBill
- fromWhere
- findItemsOver20
- findItemsOver
- mostProfitableDepartment
Put each function in a seperate file called <THE FUNCTION NAME>.js and make it a module using the module.exports statement.
Create a module like this:
module.exports = function(){
//you functions logic here
}
Create a corresponding test in a test folder called <THE FUNCTION NAME>.test.js for each function. Import the function to be tested using the require statement.
var functionToTest = require('../function-to-test');
Commit to Github
Add your code to git and commit to GitHub
Run your tests with Travis
Configure TravisCI to run your test every time you commit changes to GitHub. Add a Travis Badge to your project in GitHub.
To get going with Travis do this:
- Register with your GitHub account at Travis CI
- Add a
.travis.ymlfile to your project. It should look like this :
language: node_js
node_js:
- "your node version here"
-
Ensure that
mochais a development dependency in yourpackage.jsonfile. Do anpm install --save-dev mocha -
Ensure that
npm testrun your mocha tests. Add atestentry in your package.json file’sscriptsection. Add a relative path tomochalike this.node_modules/bin/mocha -
Commit all your changes to git and push it to GitHub.
You can read more about NodeJS and Travis configuration on the Travis website.