@@ -185,6 +185,38 @@ describe('Working with keys', () => {
185185 ) ;
186186 } ) ;
187187
188+ it ( 'merges temporary keys with object values when the same key is added' , ( ) => {
189+ // Prepare
190+ const logger = new Logger ( ) ;
191+
192+ // Act
193+ logger . appendKeys ( {
194+ foo : { key1 : 'bar' } ,
195+ } ) ;
196+ logger . info ( 'Hello, world!' ) ;
197+ logger . appendKeys ( {
198+ foo : { key2 : 'baz' } ,
199+ } ) ;
200+ logger . info ( 'Hello, world!' ) ;
201+
202+ // Assess
203+ expect ( console . info ) . toHaveBeenCalledTimes ( 2 ) ;
204+ expect ( console . info ) . toHaveLoggedNth (
205+ 1 ,
206+ expect . objectContaining ( {
207+ message : 'Hello, world!' ,
208+ foo : { key1 : 'bar' } ,
209+ } )
210+ ) ;
211+ expect ( console . info ) . toHaveLoggedNth (
212+ 2 ,
213+ expect . objectContaining ( {
214+ message : 'Hello, world!' ,
215+ foo : { key1 : 'bar' , key2 : 'baz' } ,
216+ } )
217+ ) ;
218+ } ) ;
219+
188220 it ( 'adds the temporary keys and clears them when calling resetKeys()' , ( ) => {
189221 // Prepare
190222 const logger = new Logger ( ) ;
@@ -283,6 +315,31 @@ describe('Working with keys', () => {
283315 ) ;
284316 } ) ;
285317
318+ it ( 'merges persistent keys with object values when the same key is added' , ( ) => {
319+ // Prepare
320+ const logger = new Logger ( {
321+ persistentKeys : {
322+ foo : { key1 : 'bar' } ,
323+ } ,
324+ } ) ;
325+
326+ // Act
327+ logger . appendPersistentKeys ( {
328+ foo : { key2 : 'baz' } ,
329+ } ) ;
330+ logger . info ( 'Hello, world!' ) ;
331+
332+ // Assess
333+ expect ( console . info ) . toHaveBeenCalledTimes ( 1 ) ;
334+ expect ( console . info ) . toHaveLoggedNth (
335+ 1 ,
336+ expect . objectContaining ( {
337+ message : 'Hello, world!' ,
338+ foo : { key1 : 'bar' , key2 : 'baz' } ,
339+ } )
340+ ) ;
341+ } ) ;
342+
286343 it ( 'overrides temporary keys when the same key is added as persistent key' , ( ) => {
287344 // Prepare
288345 const logger = new Logger ( ) ;
@@ -806,25 +863,27 @@ describe('Working with keys', () => {
806863 ) ;
807864 } ) ;
808865
809- it . each ( [ { value : null } , { value : undefined } ] ) (
810- 'handles null and undefined values when passing them to the log method ($value)' ,
811- ( { value } ) => {
812- // Prepare
813- const logger = new Logger ( ) ;
866+ it . each ( [
867+ { value : null } ,
868+ { value : undefined } ,
869+ ] ) ( 'handles null and undefined values when passing them to the log method ($value)' , ( {
870+ value,
871+ } ) => {
872+ // Prepare
873+ const logger = new Logger ( ) ;
814874
815- // Act
816- // @ts -expect-error - these values are already forbidden by TypeScript, but JavaScript-only customers might pass them
817- logger . info ( 'foo' , value ) ;
875+ // Act
876+ // @ts -expect-error - these values are already forbidden by TypeScript, but JavaScript-only customers might pass them
877+ logger . info ( 'foo' , value ) ;
818878
819- // Assess
820- expect ( console . info ) . toHaveLoggedNth (
821- 1 ,
822- expect . objectContaining ( {
823- message : 'foo' ,
824- } )
825- ) ;
826- }
827- ) ;
879+ // Assess
880+ expect ( console . info ) . toHaveLoggedNth (
881+ 1 ,
882+ expect . objectContaining ( {
883+ message : 'foo' ,
884+ } )
885+ ) ;
886+ } ) ;
828887
829888 describe ( 'deprecated persistentLogAttributes usage' , ( ) => {
830889 it ( 'sets #attributesStore on the logger' , ( ) => {
0 commit comments