-
Notifications
You must be signed in to change notification settings - Fork 89
/
with_args_expectation.js
49 lines (41 loc) · 1.22 KB
/
with_args_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
var oop = require('../oop');
var util = require('util');
var Expectation = require('../expectation');
function WithArgsExpectation(properties) {
this._args = null;
Expectation.call(this, properties);
}
oop.inherits(WithArgsExpectation, Expectation);
module.exports = WithArgsExpectation;
WithArgsExpectation.create = function(trace) {
var args = Array.prototype.slice.call(arguments, 1);
return new WithArgsExpectation({
_trace: trace,
_args: args,
});
};
WithArgsExpectation.prototype.diff = function(fakeCall, expectedCall) {
var expected = this._args;
var got = fakeCall.getArgs();
if (expected.length !== got.length) {
return {
reason: 'Unexpected argument count',
expected: expected.length + ' argument' + (expected.length === 1 ? '' : 's'),
got: got.length + ' argument' + (got.length === 1 ? '' : 's'),
};
}
for (var i = 0; i < expected.length; i++) {
if (expected[i] !== got[i]) {
return {
reason: 'Unexpected argument #' + (i + 1),
expected: util.inspect(expected[i]),
got: util.inspect(got[i]),
};
}
}
};
WithArgsExpectation.prototype.inspect = function() {
return args = this._args
.map(util.inspect)
.join(', ');
};