- Create a test project/framework for an existing app
- Install a test runner
- Set the test runner to run when
npm test
is called - Install an assertion library
- Run the "test suite" with a green result
None
- Pre-req: Visual Studio Code is installed
- Pre-req: Git is installed
- Clone the Demo repository:
git clone https://github.com/mjhilton/testing-workshop-demos
- Check out the Start Point for Prac 1:
git checkout Prac01-StartPoint
- This references a defined tag in the repository, you must use exactly this name
- Create a branch to make your changes on without impacting the main repo:
git checkout -b Prac01
- This branch is your own working space, you can call it anything you want
- Install Mocha and add it as a dev dependency for our project
- Install Chai and add it as a dev dependency for our project
- Update your
package.json
so that mocha is executed whennpm test
is called - Create an empty test file under the
test
folder - Run
npm test
and ensure the result is green/no errors: "0 passing"
Here's a step-by-step walkthrough of the practical steps, for if you get stuck :)
- Install Mocha and add it as a dev dependency for our project
npm install --save-dev Mocha
- Install Chai and add it as a dev dependency for our project
npm install --save-dev chai
- Update your
package.json
so that mocha is executed whennpm test
is called- Open
package.json
- Find the
scripts
array - Ensure it contains a test script, which executes mocha, like this:
"scripts": { "test": "mocha" }
- Open
- Create an empty test file under the
test
folder- Call it
name-to-number-service-tests.js
- Call it
- Run
npm test
and ensure the result is green/no errors: "0 passing"