forked from twada/empower-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecorate.js
More file actions
59 lines (49 loc) · 1.67 KB
/
decorate.js
File metadata and controls
59 lines (49 loc) · 1.67 KB
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
59
'use strict';
var some = require('core-js/library/fn/array/some');
var map = require('core-js/library/fn/array/map');
var slice = Array.prototype.slice;
function decorate (callSpec, decorator) {
var numArgsToCapture = callSpec.numArgsToCapture;
return function decoratedAssert () {
var context, message, hasMessage = false, args = slice.apply(arguments);
if (numArgsToCapture === (args.length - 1)) {
message = args.pop();
hasMessage = true;
}
var invocation = {
values: args,
message: message,
hasMessage: hasMessage
};
if (some(args, isCaptured)) {
invocation.values = map(args.slice(0, numArgsToCapture), function (arg) {
if (isNotCaptured(arg)) {
return arg;
}
if (!context) {
context = {
source: arg.source,
args: []
};
}
context.args.push({
value: arg.powerAssertContext.value,
events: arg.powerAssertContext.events
});
return arg.powerAssertContext.value;
});
return decorator.concreteAssert(callSpec, invocation, context);
} else {
return decorator.concreteAssert(callSpec, invocation);
}
};
}
function isNotCaptured (value) {
return !isCaptured(value);
}
function isCaptured (value) {
return (typeof value === 'object') &&
(value !== null) &&
(typeof value.powerAssertContext !== 'undefined');
}
module.exports = decorate;