Unit testing in the world of javascript
Unit testings main purpose is to do one thing, test the code you write
No testing it in the browser does't count. The purpose of testing is so later on say you want to add/edit a feature, you don't have to worry about what will break. Your tests will verify that all of your functionality is still intact.
It's a good idea to build out your testing setup and environment as you write your code to keeps things on a 1 to 1 basis. This also helps with groups working on the same codebase, if one of your team adds in new code, and it breaks a unit test well I suggest that code doesn't go any further.
This is also the easiest approach it makes sure your code is indeed testable, and stays that way as you advence and your app becomes larger and more complex.
You want to make sure you ALWAYS test all of your code as much as possible and from as many different use cases that you can think of.
If you're using external libraries like a JavaScript framework, or utility library like underscore
since these are usually already well tested, if not then I may start to question your judgement.
- Clone the repo
- Open repo and run
npm i
- Run one of the following commands:
npm run test:01
- Run the simple testsnpm run test:02-user
- Run the user testsnpm run test:02-weather
- Run the weather testsnpm run test:03
- Run the example 3 testsnpm run test:04
- Run the example 4 testsnpm run test:04:tapspec
- Run the example 4 tests with the tap-spec formattingnpm run test:activity
- Run the activity tests (Usestap-spec
formatting)npm run test:mocha
- Run the mocha example activitynpm run test:titleize
- Run the titleize SOLVED unit testsnpm run test:disemvowel
- Run the disemvowel SOLVED unit testsnpm run test:tax
- Run the tax SOLVED unit testsnpm test
- Runs all of the example tests