UNPKG

1.24 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const lodash_1 = require("../wrap/lodash");
4class Double {
5 static create(name, real, parent, fakeCreator) {
6 const double = new Double(name, real, parent);
7 if (fakeCreator)
8 double.fake = fakeCreator(double);
9 return double;
10 }
11 constructor(name, real, parent) {
12 this.name = name;
13 this.real = real;
14 this.children = new Set();
15 if (parent) {
16 this.parent = parent;
17 parent.addChild(this);
18 }
19 }
20 addChild(child) {
21 this.children.add(child);
22 child.parent = this;
23 }
24 get fullName() {
25 if (!lodash_1.default.some(lodash_1.default.map(this.ancestors, 'name')))
26 return this.name;
27 return lodash_1.default.map(this.ancestors.concat(this), (ancestor) => ancestor.name == null ? '(unnamed)' : ancestor.name).join('.');
28 }
29 get ancestors() {
30 if (!this.parent)
31 return [];
32 return this.parent.ancestors.concat(this.parent);
33 }
34 toString() {
35 return this.fullName == null ? '[test double (unnamed)]' : `[test double for "${this.fullName}"]`;
36 }
37}
38exports.default = Double;