forked from ryan-roemer/backbone-testing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmocks.spec.js
More file actions
31 lines (24 loc) · 758 Bytes
/
Copy pathmocks.spec.js
File metadata and controls
31 lines (24 loc) · 758 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
describe("Sinon.JS mocks", function () {
// Object literal with two methods.
var obj = {
multiply: function (a, b) { return a * b; },
error: function (msg) { throw new Error(msg); }
};
it("mocks multiply", function () {
// Create the mock.
var mock = sinon.mock(obj);
// The multiply method is expected to be called:
mock.expects("multiply")
.atLeast(2) // 2+ times,
.atMost(4) // no more than 4 times, and
.withArgs(2); // 2 was first arg on *all* calls.
// Make 3 calls to `multiply()`.
obj.multiply(2, 1);
obj.multiply(2, 2);
obj.multiply(2, 3);
// Verify **all** of the previous expectations.
mock.verify();
// Restore the object.
mock.restore();
});
});