-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathspy.js
45 lines (42 loc) · 1.18 KB
/
spy.js
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
32
33
34
35
36
37
38
39
40
41
42
43
44
var SpyExpectation = require("./spy-expectation");
module.exports = createSpy;
function createSpy(identity, spied) {
console.warn("Jasmine-style spies are deprecated. Consider using `sinon` or another.");
function spy() {
var args = Array.prototype.slice.call(arguments)
var call = {
args: args
};
spy.mostRecentCall = call;
spy.argsForCall.push(call.args);
spy.calls.push(call);
spy.callCount++;
if (spy.callThrough) {
return spy.spied.apply(this, arguments);
}
}
spy.identity = identity;
spy.calls = [];
spy.argsForCall = [];
spy.spied = spied;
spy.callThrough = false;
spy.callCount = 0;
spy.andCallFake = function (fake) {
spy.spied = fake;
spy.callThrough = true;
};
spy.andCallThrough = function () {
spy.callThrough = true;
};
spy.andReturn = function (value) {
spy.callThrough = true;
spy.spied = function () {
return value;
};
};
spy.expect = function () {
return expectation;
};
var expectation = new SpyExpectation(spy, getCurrentReport());
return spy;
}