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