WHITECOLOR
WHITECOLOR

Reputation: 26122

What are alternatives for Sinon.js (JS mocking library)?

Are there any worthwhile alternatives for Sinon.js?

Thanks.

Upvotes: 6

Views: 5068

Answers (3)

Adam
Adam

Reputation: 11

I just started a new project called candy-wrapper that may be an alternative to Sinon in some instances: https://www.npmjs.com/package/candy-wrapper

Here are some examples of how to use it, I would love feedback if anyone has any insights as to how to make it better:

var Wrapper = require("candy-wrapper");

// a simple test object
var myDrone = {
    name: "DJI",
    fly: function(direction) {
        return true;
    }
}

new Wrapper(myDrone, "name");
new Wrapper(myDrone, "fly");

myDrone.fly("north");
myDrone.fly("west");

// evaluating previous calls through the 'historyList' and 'Filters'
myDrone.fly.historyList.filterFirst().expectCallArgs("north"); // true
myDrone.fly.historyList.filterSecond().expectCallArgs("east"); // false
myDrone.fly.expectReportAllFailtures(); // throws an error about the "east" expecation failing

// modifying behavior using 'Triggers'
myDrone.fly.triggerOnCallArgs("east").actionReturn(false); // will return 'false' when called with "east"
myDrone.fly("east"); // false
myDrone.fly("west"); // true (the default return value)

// working with properties
myDrone.name.triggerOnSet().actionThrowException(new Error("do not set the name"));
myDrone.name = "Bob"; // throws Error: "do not set the name"
var ret = myDrone.name; // ret = "DJI"

Upvotes: 0

Inanc Gumus
Inanc Gumus

Reputation: 27889

Testdouble.js

There is also library called testdouble.js. Which is a kind of more object-oriented than sinon.js.

Also, this article from testdouble guys explain the differences between sinon.js and testdouble.js.

Example

var td = require('testdouble');

var fetch = td.function();
td.when(fetch(42)).thenReturn('Jane User');

fetch(42); // -> 'Jane User'

Upvotes: 2

Tanzeeb Khalili
Tanzeeb Khalili

Reputation: 7344

Not quite as advanced, but you can look at Jack.

Upvotes: 1

Related Questions