This post enlighten by Jasmine JavaScript Testing
Unit Test, Karma, Jasmine
Posted on
My current job content is developing and maintaining a web application which written in PHP. It requires same Javascript for front-end, but our team current development process based on others teams requirements:
When they ask, we developโฆ๐
No time line, no strictly requirement, all work check and test done by visual result in browser.
After working on current project for over 6 months, I realized I have no any efficiency process to test my Javascript code (no any test for PHP side either). I wanna try on Karma and Jasmine on our PHP MVC framework, only do unit test for my Javascript part, no plan for PHP code so far.
Task break down
- set up environment
- write unit test case for current exist Javascript file
- run and debug
- repeat step 2, step 3
Set up test environment in current project
- Initiated a
Node.js
project under the current project directory
|
|
- Install
Karma
,Jasmine
,minimatch
and others dependencies base on installation result
|
|
- Configure
karma.conf.js
, see configuration instruction here. SelectJasmine
as frameworks. - Specify file paths in
karma.conf.js
, add current project dependencies such asjQuery
,Bootstrap
and other Javascript libraries if necessary. - Finally specify the unit test file and source file path in
karma.conf.js
, for example:
|
|
using minimatch
to have more control on file selection.