var stub = sinon.stub(); var opts = { call: function (msg) { console.log(msg); } }; // We can control how the sinon.stub() will behave based on how it’s called! stub.withArgs("Hello").returns("World"); stub.withArgs("Wuz").returns("Zup?"); stub.withArgs("Kapow").throws(); stub.withArgs(opts).yieldsTo("call", ["Howdy"]); stub("Hello"); // "World" stub(opts); // "Howdy"