Browse Source

test(core): Add a couple of test cases to mergeConfig spec

Michael Bromley 5 years ago
parent
commit
bea9f75d3d
1 changed files with 43 additions and 0 deletions
  1. 43 0
      packages/core/src/config/merge-config.spec.ts

+ 43 - 0
packages/core/src/config/merge-config.spec.ts

@@ -42,10 +42,53 @@ describe('mergeConfig()', () => {
         });
         });
     });
     });
 
 
+    it('does not mutate target', () => {
+        const input: any = {
+            a: 1,
+            b: { c: { d: 'foo', e: { f: 1 } } },
+        };
+
+        const result = mergeConfig(input, { b: { c: { d: 'bar' } } } as any);
+        expect(result).toEqual({
+            a: 1,
+            b: { c: { d: 'bar', e: { f: 1 } } },
+        });
+        expect(input).toEqual({
+            a: 1,
+            b: { c: { d: 'foo', e: { f: 1 } } },
+        });
+    });
+
+    it('works when nested', () => {
+        const input1: any = {
+            a: 1,
+            b: { c: { d: 'foo1', e: { f: 1 } } },
+        };
+
+        const input2: any = {
+            b: { c: { d: 'foo2', e: { f: 2 } } },
+        };
+
+        const result = mergeConfig(input1, mergeConfig(input2, { b: { c: { d: 'bar' } } } as any));
+
+        expect(result).toEqual({
+            a: 1,
+            b: { c: { d: 'bar', e: { f: 2 } } },
+        });
+        expect(input1).toEqual({
+            a: 1,
+            b: { c: { d: 'foo1', e: { f: 1 } } },
+        });
+        expect(input2).toEqual({
+            b: { c: { d: 'foo2', e: { f: 2 } } },
+        });
+    });
+
     it('replaces class instances rather than merging their properties', () => {
     it('replaces class instances rather than merging their properties', () => {
         class Foo {
         class Foo {
             name = 'foo';
             name = 'foo';
         }
         }
+
         class Bar {
         class Bar {
             name = 'bar';
             name = 'bar';
         }
         }