Install sinon with jasmine and Karma

lately I wanted to use sinon within karma. So I simply did the following :

install sinon with bower : bower install sinon

then added the sinon.js to the karma files in the karma.conf.js like so :

files: [

and use it in my jasmine test specs file…. but it didn’t work.

And here is the solution:

in a command prompt, navigate to the root of your project and type :

npm install karma-sinon --save-dev

then in your karma.conf.js file add the following:

frameworks: ['jasmine', 'sinon']

You can now use sinon in your jasmine files

var mySUT = {
    callCallback: function (cb) {

 describe('spies', function () {
        it('should spy on a callback', function(){
            var spy = sinon.spy();  

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s