@@ -5,108 +5,115 @@ var assert = require('chai').assert;
55var apply = require ( '../../lib/apply' ) ;
66
77describe ( 'apply' , function ( ) {
8- it ( 'should replace an attribute' , function ( ) {
9- assert . deepEqual (
10- apply ( { a : 'b' } , { a : 'c' } ) ,
8+ it ( 'should replace an attribute' , function ( ) {
9+ assert . deepEqual (
10+ apply ( { a : 'b' } , { a : 'c' } ) ,
1111 { a : 'c' }
1212 ) ;
13- } ) ;
13+ } ) ;
1414
15- it ( 'should add an attribute' , function ( ) {
16- assert . deepEqual (
17- apply ( { a : 'b' } , { b : 'c' } ) ,
15+ it ( 'should add an attribute' , function ( ) {
16+ assert . deepEqual (
17+ apply ( { a : 'b' } , { b : 'c' } ) ,
1818 { a : 'b' , b : 'c' }
1919 ) ;
20- } ) ;
20+ } ) ;
2121
22- it ( 'should delete attribute' , function ( ) {
23- assert . deepEqual (
24- apply ( { a : 'b' } , { a : null } ) ,
22+ it ( 'should delete attribute' , function ( ) {
23+ assert . deepEqual (
24+ apply ( { a : 'b' } , { a : null } ) ,
2525 { }
2626 ) ;
27- } ) ;
27+ } ) ;
2828
29- it ( 'should delete attribute without affecting others' , function ( ) {
30- assert . deepEqual (
31- apply ( { a : 'b' , b : 'c' } , { a : null } ) ,
29+ it ( 'should delete attribute without affecting others' , function ( ) {
30+ assert . deepEqual (
31+ apply ( { a : 'b' , b : 'c' } , { a : null } ) ,
3232 { b : 'c' }
3333 ) ;
34- } ) ;
34+ } ) ;
3535
36- it ( 'should replace array with a string' , function ( ) {
37- assert . deepEqual (
38- apply ( { a : [ 'b' ] } , { a : 'c' } ) ,
36+ it ( 'should replace array with a string' , function ( ) {
37+ assert . deepEqual (
38+ apply ( { a : [ 'b' ] } , { a : 'c' } ) ,
3939 { a : 'c' }
4040 ) ;
41- } ) ;
41+ } ) ;
4242
43- it ( 'should replace an string with an array' , function ( ) {
44- assert . deepEqual (
45- apply ( { a : 'c' } , { a : [ 'b' ] } ) ,
43+ it ( 'should replace an string with an array' , function ( ) {
44+ assert . deepEqual (
45+ apply ( { a : 'c' } , { a : [ 'b' ] } ) ,
4646 { a : [ 'b' ] }
4747 ) ;
48- } ) ;
48+ } ) ;
4949
50- it ( 'should apply recursively' , function ( ) {
51- assert . deepEqual (
52- apply ( { a : { b : 'c' } } , { a : { b : 'd' , c : null } } ) ,
50+ it ( 'should apply recursively' , function ( ) {
51+ assert . deepEqual (
52+ apply ( { a : { b : 'c' } } , { a : { b : 'd' , c : null } } ) ,
5353 { a : { b : 'd' } }
5454 ) ;
55- } ) ;
55+ } ) ;
5656
57- it ( 'should replace an object array with a number array' , function ( ) {
58- assert . deepEqual (
59- apply ( { a : [ { b : 'c' } ] } , { a : [ 1 ] } ) ,
57+ it ( 'should replace an object array with a number array' , function ( ) {
58+ assert . deepEqual (
59+ apply ( { a : [ { b : 'c' } ] } , { a : [ 1 ] } ) ,
6060 { a : [ 1 ] }
6161 ) ;
62- } ) ;
62+ } ) ;
6363
64- it ( 'should replace an array' , function ( ) {
65- assert . deepEqual (
66- apply ( [ 'a' , 'b' ] , [ 'c' , 'd' ] ) ,
67- [ 'c' , 'd' ]
64+ it ( 'should replace an array' , function ( ) {
65+ assert . deepEqual (
66+ apply ( [ 'a' , 'b' ] , [ 'c' , 'd' ] ) ,
67+ [ 'c' , 'd' ]
6868 ) ;
69- } ) ;
69+ } ) ;
7070
71- it ( 'should replace an object with an array' , function ( ) {
72- assert . deepEqual (
73- apply ( { a : 'b' } , [ 'c' ] ) ,
74- [ 'c' ]
71+ it ( 'should replace an object with an array' , function ( ) {
72+ assert . deepEqual (
73+ apply ( { a : 'b' } , [ 'c' ] ) ,
74+ [ 'c' ]
7575 ) ;
76- } ) ;
76+ } ) ;
7777
78- it ( 'should replace an object with null' , function ( ) {
79- assert . deepEqual (
80- apply ( { a : 'foo' } , null ) ,
81- null
78+ it ( 'should replace an object with null' , function ( ) {
79+ assert . deepEqual (
80+ apply ( { a : 'foo' } , null ) ,
81+ null
8282 ) ;
83- } ) ;
83+ } ) ;
8484
85- it ( 'should replace an object with a string ' , function ( ) {
86- assert . deepEqual (
87- apply ( { a : 'foo' } , 'bar' ) ,
88- 'bar'
85+ it ( 'should replace with an object implementing toJSON() method ' , function ( ) {
86+ assert . deepEqual (
87+ apply ( { a : 'foo' } , { a : new Date ( '2020-05-09T00:00:00.000Z' ) } ) ,
88+ { a : '2020-05-09T00:00:00.000Z' }
8989 ) ;
90- } ) ;
90+ } ) ;
9191
92- it ( 'should not change null attributes ' , function ( ) {
93- assert . deepEqual (
94- apply ( { e : null } , { a : 1 } ) ,
95- { e : null , a : 1 }
92+ it ( 'should replace an object with a string ' , function ( ) {
93+ assert . deepEqual (
94+ apply ( { a : 'foo' } , 'bar' ) ,
95+ 'bar'
9696 ) ;
97- } ) ;
97+ } ) ;
9898
99- it ( 'should not set an attribute to null' , function ( ) {
100- assert . deepEqual (
101- apply ( [ 1 , 2 ] , { a : 'b' , c : null } ) ,
102- { a : 'b' }
99+ it ( 'should not change null attributes ' , function ( ) {
100+ assert . deepEqual (
101+ apply ( { e : null } , { a : 1 } ) ,
102+ { e : null , a : 1 }
103103 ) ;
104- } ) ;
104+ } ) ;
105105
106- it ( 'should not set an attribute to null in a sub object' , function ( ) {
107- assert . deepEqual (
108- apply ( { } , { a : { bb : { ccc : null } } } ) ,
109- { a : { bb : { } } }
110- ) ;
111- } ) ;
106+ it ( 'should not set an attribute to null' , function ( ) {
107+ assert . deepEqual (
108+ apply ( [ 1 , 2 ] , { a : 'b' , c : null } ) ,
109+ { a : 'b' }
110+ ) ;
111+ } ) ;
112+
113+ it ( 'should not set an attribute to null in a sub object' , function ( ) {
114+ assert . deepEqual (
115+ apply ( { } , { a : { bb : { ccc : null } } } ) ,
116+ { a : { bb : { } } }
117+ ) ;
118+ } ) ;
112119} ) ;
0 commit comments