1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const _ = require("lodash");
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | function default_1(object, path, value) {
|
9 | if (object === undefined || path === undefined)
|
10 | throw new Error('should not be undefined');
|
11 | return {
|
12 | run(ctx) {
|
13 | ctx.stubs = ctx.stubs || [];
|
14 | const descriptor = Object.getOwnPropertyDescriptor(object, path);
|
15 | if (descriptor && descriptor.get) {
|
16 | ctx.stubs.push(descriptor.get);
|
17 | descriptor.get = value;
|
18 | Object.defineProperty(object, path, descriptor);
|
19 | }
|
20 | else {
|
21 | ctx.stubs.push(_.get(object, path));
|
22 | _.set(object, path, value);
|
23 | }
|
24 | }, finally(ctx) {
|
25 | const stub = ctx.stubs.pop();
|
26 | const descriptor = Object.getOwnPropertyDescriptor(object, path);
|
27 | if (descriptor && descriptor.get) {
|
28 | descriptor.get = stub;
|
29 | Object.defineProperty(object, path, descriptor);
|
30 | }
|
31 | else {
|
32 | _.set(object, path, stub);
|
33 | }
|
34 | },
|
35 | };
|
36 | }
|
37 | exports.default = default_1;
|