[ karma ] AngularJS testing framework

What is Karma ?

Karma is a direct product of the AngularJS team from struggling to test their own framework features with existing tools.

Karma also provides you options to replace “Jasmine” ( javascript test framework ) with other testing frameworks such as Mocha and QUnit or integrate with various continuous integration services like Jenkins, TravisCI, or CircleCI.

ref : https://scotch.io/tutorials/testing-angularjs-with-jasmine-and-karma-part-1

Installation

npm install karma karma-chrome-launcher

configuration example

https://github.com/karma-runner/karma/blob/master/test/client/karma.conf.js

karma.conf.js

// karma.conf.js
module.exports = function(config) {
config.set({
frameworks: ['jasmine'],

// list of files / patterns to load in the browser

files: [
'*.js'
]
})
}

“var files” relative path relative to “var basePath”, “var basePath” relative path relative to this config file.

autoWatch : true  ( if file changes, auto run a test )

spec

dump variable to a console

dump(variable)

ref : https://karma-runner.github.io/latest/intro/configuration.html

Running the local karma in node_packages

npm install -g karma-cli

ref : http://stackoverflow.com/questions/34947045/how-do-you-run-karma-after-installation

<strong>Run&nbsp;</strong>
<pre>

karma start karma.conf.js --single-run --browsers PhantomJS,Chrome,Firefox,Safari

Example

https://github.com/dsin/hello-karma

Jasmine Example

https://github.com/dsin/jasminetest/blob/master/spec/jasminetest.spec.js

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s