-
Notifications
You must be signed in to change notification settings - Fork 3
/
spy-expectation.js
59 lines (52 loc) · 1.56 KB
/
spy-expectation.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var Expectation = require("./expectation");
module.exports = SpyExpectation;
function SpyExpectation(value, report) {
Expectation.call(this, value, report);
}
SpyExpectation.prototype = Object.create(Expectation.prototype);
SpyExpectation.prototype.constructor = SpyExpectation;
SpyExpectation.prototype.toHaveBeenCalled = function () {
if (this.value.displayName) {
this.assert(this.value.argsForCall.length > 0, [
"expected function", "[not] to have been called"
], [
this.value.displayName
]);
} else {
this.assert(this.value.argsForCall.length > 0, [
"expected function [not] to have been called"
], []);
}
};
SpyExpectation.prototype.toHaveBeenCalledWith = function () {
var args = Array.prototype.slice.call(arguments);
var guard = Object.has(this.value.argsForCall, args, Object.equals);
if (this.value.displayName) {
this.assert(
guard,
[
"expected function",
"[not] to have been called with",
"but had only these calls"
],
[
this.value.displayName,
args,
this.value.argsForCall
]
);
} else {
this.assert(
guard,
[
"expected function " +
"[not] to have been called with",
"but had only these calls"
],
[
args,
this.value.argsForCall
]
);
}
};