blob: eddfadb9ee3f721e1987a35a9e3a32030e400af7 (
plain)
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
|
'use strict'
function Mock() {
let out = function() {
out.calledWith = Array.from(arguments);
}
return out;
}
function stub(name, value) {
let parts = name.split('.'),
last = parts.pop(),
part = global;
parts.forEach(partName => {
if (!part.hasOwnProperty(partName)) {
part[partName] = {};
}
part = part[partName];
});
part[last] = value;
}
function stubber(namesValues) {
namesValues.forEach(nameValue => {
stub(...nameValue);
});
}
Object.assign(exports, {Mock, stub, stubber});
|