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

Are there any worthwhile alternatives for Sinon.js?

Thank.

+5
source share
3 answers

Not quite advanced, but you can watch Jack .

+1
source

Testdouble.js

There is also a library called testdouble.js . This is something more object oriented than sinon.js.

In addition, this article from testdouble contributes to 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'
+1
source

candy-wrapper, Sinon : https://www.npmjs.com/package/candy-wrapper

, , , - , :

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"
0

All Articles