LEVELING UP

Player 3 ๐Ÿ‘ถ๐Ÿป has entered the game


  • home

  • code

  • archives

  • tags

  • resume

Jasmine JavaScript Testing

Posted on 10-06-2016

This post enlighten by Jasmine JavaScript Testing

Read more »

Unit Test, Karma, Jasmine

Posted on 10-05-2016

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
  1. set up environment
  2. write unit test case for current exist Javascript file
  3. run and debug
  4. repeat step 2, step 3
Set up test environment in current project
  1. Initiated a Node.js project under the current project directory
1
npm init
  1. Install Karma, Jasmine, minimatch and others dependencies base on installation result
1
2
3
4
npm install karma --save-dev
npm install karma-cli -g
npm install karma-jasmine --save-dev
npm install minimatch --save-dev
  1. Configure karma.conf.js, see configuration instruction here. Select Jasmine as frameworks.
  2. Specify file paths in karma.conf.js, add current project dependencies such as jQuery, Bootstrap and other Javascript libraries if necessary.
  3. Finally specify the unit test file and source file path in karma.conf.js, for example:
1
2
3
4
files: [
'www/js/*.js', // source file path
'test/www/js/*Spec.js' // unit test file path
]

using minimatch to have more control on file selection.

Write unit test in *Spec.js
โ‡…
Debug and write more unit test
1…34
nehcob

nehcob

a tiny player of massively multiplayer online role-playing game named EARTH ONLINE

32 posts
39 tags
© 2019 nehcob
Powered by Hexo
Theme - NexT.Muse