Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including karma-sinon with all npm packages installed. Try it out:

require("karma/package.json"); // karma is a peer dependency. require("sinon/package.json"); // sinon is a peer dependency. var karmaSinon = require("karma-sinon")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

karma-sinon v1.0.5

Sinon for Karma

karma-sinon

Sinon for karma

Installation

Install the module via npm

$ npm install karma-sinon sinon --save-dev

Add sinon to the frameworks key in your Karma configuration:

module.exports = function(config) {
  'use strict';
  config.set({
    #...
    frameworks: ['jasmine', 'sinon'],
    #...
  });
}

Example

describe("sinon example test", function () {
    var time2013_10_01;

    time2013_10_01 = (new Date(2013, 10-1, 1)).getTime();

    before(function() {
        // sinon was defined in global scope
        this.fakeTimer = new sinon.useFakeTimers(time2013_10_01);
    });

    it("some test", function() {
        //test
    });

    after(function() {
        this.fakeTimer.restore();
    });

});
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free