Installation:
[sudo] npm install .
Ubuntu
On Ubuntu you might be able to use the scripts/install-ubuntu.sh
script. Have a look and give it a try
Requirements
- node.js > 0.10
- npm
Used libraries
- Karma
- Chai
- Mocha
- You need more assertions? Have a look at Chai plugins
File structure
We do not have a general tests
folder containing all test files. Instead we create a file having the same name appended by .spec.js
in the same directory.
For instance you want to test a file named startfrom.js
then we create a file named startfrom.spec.js
:
plugins/CoreHome/angularjs/common/filters/startfrom.js
=>
plugins/CoreHome/angularjs/common/filters/startfrom.spec.js
Execution
Run tests and run them automatically again once there is a file change:
karma start karma.conf.js
Run test suites only once:
karma start karma.conf.js --single-run
Run test suites in a different browser:
karma start karma.conf.js --browsers Chrome
Run tests in different browser permanently:
You can change the browsers: ['Chrome', 'Firefox', 'PhantomJS']
property in karma.conf.js
but you might have to be careful to not commit this change.
Before executing a test it'll always run JSHint to detect and report possible problems in the JavaScript code.
Testing existing jQuery code
Just in case you want to write a test for your jQuery code you can do this the same way. You might be interested in the Chai jQuery plugin.
Examples
- Testing a filter
- Testing a directive
- Testing a service/provider/factory/model
- See more examples in AngularJS guide