@@ -19,7 +19,14 @@ describe( 'Config', () => {
1919 path : 'xyz'
2020 }
2121 } ,
22- toolbar : 'top'
22+ toolbar : 'top' ,
23+ options : {
24+ foo : [
25+ { bar : 'b' } ,
26+ { bar : 'a' } ,
27+ { bar : 'z' }
28+ ]
29+ }
2330 } ) ;
2431 } ) ;
2532
@@ -334,7 +341,7 @@ describe( 'Config', () => {
334341 expect ( config . get ( 'resize.icon.path' ) ) . to . equal ( 'xyz' ) ;
335342 } ) ;
336343
337- it ( 'should retrieve a object of the configuration' , ( ) => {
344+ it ( 'should retrieve an object of the configuration' , ( ) => {
338345 const resize = config . get ( 'resize' ) ;
339346
340347 expect ( resize ) . to . be . an ( 'object' ) ;
@@ -371,5 +378,33 @@ describe( 'Config', () => {
371378 config . resize . maxHeight ;
372379 } ) . to . throw ( ) ;
373380 } ) ;
381+
382+ it ( 'should not be possible to alter config object by altering returned value' , ( ) => {
383+ expect ( config . get ( 'resize.icon.path' ) ) . to . equal ( 'xyz' ) ;
384+
385+ const icon = config . get ( 'resize.icon' ) ;
386+ icon . path = 'foo/bar' ;
387+
388+ expect ( config . get ( 'resize.icon.path' ) ) . to . equal ( 'xyz' ) ;
389+
390+ const resize = config . get ( 'resize' ) ;
391+ resize . icon . path = 'foo/baz' ;
392+
393+ expect ( config . get ( 'resize.icon.path' ) ) . to . equal ( 'xyz' ) ;
394+ } ) ;
395+
396+ it ( 'should not be possible to alter array in config by altering returned value' , ( ) => {
397+ expect ( config . get ( 'options.foo' ) ) . to . deep . equal ( [ { bar : 'b' } , { bar : 'a' } , { bar : 'z' } ] ) ;
398+
399+ const fooOptions = config . get ( 'options.foo' ) ;
400+ fooOptions . pop ( ) ;
401+
402+ expect ( config . get ( 'options.foo' ) ) . to . deep . equal ( [ { bar : 'b' } , { bar : 'a' } , { bar : 'z' } ] ) ;
403+
404+ const options = config . get ( 'options' ) ;
405+ options . foo . pop ( ) ;
406+
407+ expect ( config . get ( 'options.foo' ) ) . to . deep . equal ( [ { bar : 'b' } , { bar : 'a' } , { bar : 'z' } ] ) ;
408+ } ) ;
374409 } ) ;
375410} ) ;
0 commit comments