Skip to content

Commit f4ddd87

Browse files
committed
expand test coverage a smidge
1 parent b63f93c commit f4ddd87

File tree

2 files changed

+51
-8
lines changed

2 files changed

+51
-8
lines changed

src/legacy/server/config/override.test.ts

Lines changed: 50 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,60 @@ describe('override(target, source)', function() {
3737
client: {
3838
type: 'nosql',
3939
},
40+
foo: {
41+
bar: {
42+
baz: 1,
43+
},
44+
},
4045
},
4146
};
4247

43-
expect(override(target, source)).toEqual({
44-
test: {
45-
enable: true,
46-
host: ['host-01', 'host-02'],
47-
client: {
48-
type: 'nosql',
48+
expect(override(target, source)).toMatchInlineSnapshot(`
49+
Object {
50+
"test": Object {
51+
"client": Object {
52+
"type": "nosql",
53+
},
54+
"enable": true,
55+
"foo": Object {
56+
"bar": Object {
57+
"baz": 1,
58+
},
59+
},
60+
"host": Array [
61+
"host-01",
62+
"host-02",
63+
],
4964
},
65+
}
66+
`);
67+
});
68+
69+
it('does not mutate arguments', () => {
70+
const target = {
71+
foo: {
72+
bar: 1,
73+
baz: 1,
74+
},
75+
};
76+
77+
const source = {
78+
foo: {
79+
bar: 2,
5080
},
51-
});
81+
box: 2,
82+
};
83+
84+
expect(override(target, source)).toMatchInlineSnapshot(`
85+
Object {
86+
"box": 2,
87+
"foo": Object {
88+
"bar": 2,
89+
"baz": 1,
90+
},
91+
}
92+
`);
93+
expect(target).not.toHaveProperty('box');
94+
expect(source.foo).not.toHaveProperty('baz');
5295
});
5396
});

src/legacy/server/config/override.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const assignDeep = (target: Record<string, any>, source: Record<string, any>) =>
3434
}
3535
};
3636

37-
const override = (...sources: Array<Record<string, any>>): Record<string, any> => {
37+
export const override = (...sources: Array<Record<string, any>>): Record<string, any> => {
3838
const result = {};
3939

4040
for (const object of sources) {

0 commit comments

Comments
 (0)