14
14
var update = require ( 'update' ) ;
15
15
16
16
describe ( 'update' , ( ) => {
17
-
18
17
describe ( '$push' , ( ) => {
19
18
it ( 'pushes' , ( ) => {
20
19
expect ( update ( [ 1 ] , { $push : [ 7 ] } ) ) . toEqual ( [ 1 , 7 ] ) ;
@@ -27,12 +26,12 @@ describe('update', () => {
27
26
it ( 'only pushes an array' , ( ) => {
28
27
expect ( update . bind ( null , [ ] , { $push : 7 } ) ) . toThrowError (
29
28
'update(): expected spec of $push to be an array; got 7. Did you ' +
30
- 'forget to wrap your parameter in an array?'
29
+ 'forget to wrap your parameter in an array?' ,
31
30
) ;
32
31
} ) ;
33
32
it ( 'only pushes unto an array' , ( ) => {
34
33
expect ( update . bind ( null , 1 , { $push : 7 } ) ) . toThrowError (
35
- 'update(): expected target of $push to be an array; got 1.'
34
+ 'update(): expected target of $push to be an array; got 1.' ,
36
35
) ;
37
36
} ) ;
38
37
} ) ;
@@ -49,12 +48,12 @@ describe('update', () => {
49
48
it ( 'only unshifts an array' , ( ) => {
50
49
expect ( update . bind ( null , [ ] , { $unshift : 7 } ) ) . toThrowError (
51
50
'update(): expected spec of $unshift to be an array; got 7. Did you ' +
52
- 'forget to wrap your parameter in an array?'
51
+ 'forget to wrap your parameter in an array?' ,
53
52
) ;
54
53
} ) ;
55
54
it ( 'only unshifts unto an array' , ( ) => {
56
55
expect ( update . bind ( null , 1 , { $unshift : 7 } ) ) . toThrowError (
57
- 'update(): expected target of $unshift to be an array; got 1.'
56
+ 'update(): expected target of $unshift to be an array; got 1.' ,
58
57
) ;
59
58
} ) ;
60
59
} ) ;
@@ -71,16 +70,16 @@ describe('update', () => {
71
70
it ( 'only splices an array of arrays' , ( ) => {
72
71
expect ( update . bind ( null , [ ] , { $splice : 1 } ) ) . toThrowError (
73
72
'update(): expected spec of $splice to be an array of arrays; got 1. ' +
74
- 'Did you forget to wrap your parameters in an array?'
73
+ 'Did you forget to wrap your parameters in an array?' ,
75
74
) ;
76
75
expect ( update . bind ( null , [ ] , { $splice : [ 1 ] } ) ) . toThrowError (
77
76
'update(): expected spec of $splice to be an array of arrays; got 1. ' +
78
- 'Did you forget to wrap your parameters in an array?'
77
+ 'Did you forget to wrap your parameters in an array?' ,
79
78
) ;
80
79
} ) ;
81
80
it ( 'only splices unto an array' , ( ) => {
82
81
expect ( update . bind ( null , 1 , { $splice : 7 } ) ) . toThrowError (
83
- 'Expected $splice target to be an array; got 1'
82
+ 'Expected $splice target to be an array; got 1' ,
84
83
) ;
85
84
} ) ;
86
85
} ) ;
@@ -96,12 +95,12 @@ describe('update', () => {
96
95
} ) ;
97
96
it ( 'only merges with an object' , ( ) => {
98
97
expect ( update . bind ( null , { } , { $merge : 7 } ) ) . toThrowError (
99
- ' update(): $merge expects a spec of type \ 'object\ '; got 7'
98
+ " update(): $merge expects a spec of type 'object'; got 7" ,
100
99
) ;
101
100
} ) ;
102
101
it ( 'only merges with an object' , ( ) => {
103
102
expect ( update . bind ( null , 7 , { $merge : { a : 'b' } } ) ) . toThrowError (
104
- ' update(): $merge expects a target of type \ 'object\ '; got 7'
103
+ " update(): $merge expects a target of type 'object'; got 7" ,
105
104
) ;
106
105
} ) ;
107
106
} ) ;
@@ -131,32 +130,37 @@ describe('update', () => {
131
130
} ) ;
132
131
it ( 'only applies a function' , ( ) => {
133
132
expect ( update . bind ( null , 2 , { $apply : 123 } ) ) . toThrowError (
134
- 'update(): expected spec of $apply to be a function; got 123.'
133
+ 'update(): expected spec of $apply to be a function; got 123.' ,
135
134
) ;
136
135
} ) ;
137
136
} ) ;
138
137
139
138
it ( 'should support deep updates' , ( ) => {
140
- expect ( update ( {
141
- a : 'b' ,
142
- c : {
143
- d : 'e' ,
144
- f : [ 1 ] ,
145
- g : [ 2 ] ,
146
- h : [ 3 ] ,
147
- i : { j : 'k' } ,
148
- l : 4 ,
149
- } ,
150
- } , {
151
- c : {
152
- d : { $set : 'm' } ,
153
- f : { $push : [ 5 ] } ,
154
- g : { $unshift : [ 6 ] } ,
155
- h : { $splice : [ [ 0 , 1 , 7 ] ] } ,
156
- i : { $merge : { n : 'o' } } ,
157
- l : { $apply : ( x ) => x * 2 } ,
158
- } ,
159
- } ) ) . toEqual ( {
139
+ expect (
140
+ update (
141
+ {
142
+ a : 'b' ,
143
+ c : {
144
+ d : 'e' ,
145
+ f : [ 1 ] ,
146
+ g : [ 2 ] ,
147
+ h : [ 3 ] ,
148
+ i : { j : 'k' } ,
149
+ l : 4 ,
150
+ } ,
151
+ } ,
152
+ {
153
+ c : {
154
+ d : { $set : 'm' } ,
155
+ f : { $push : [ 5 ] } ,
156
+ g : { $unshift : [ 6 ] } ,
157
+ h : { $splice : [ [ 0 , 1 , 7 ] ] } ,
158
+ i : { $merge : { n : 'o' } } ,
159
+ l : { $apply : x => x * 2 } ,
160
+ } ,
161
+ } ,
162
+ ) ,
163
+ ) . toEqual ( {
160
164
a : 'b' ,
161
165
c : {
162
166
d : 'm' ,
@@ -172,14 +176,14 @@ describe('update', () => {
172
176
it ( 'should require a command' , ( ) => {
173
177
expect ( update . bind ( null , { a : 'b' } , { a : 'c' } ) ) . toThrowError (
174
178
'update(): You provided a key path to update() that did not contain ' +
175
- 'one of $push, $unshift, $splice, $set, $merge, $apply. Did you ' +
176
- 'forget to include {$set: ...}?'
179
+ 'one of $push, $unshift, $splice, $set, $merge, $apply. Did you ' +
180
+ 'forget to include {$set: ...}?' ,
177
181
) ;
178
182
} ) ;
179
183
180
184
it ( 'should perform safe hasOwnProperty check' , ( ) => {
181
- expect ( update ( { } , { ' hasOwnProperty' : { $set : 'a' } } ) ) . toEqual ( {
182
- ' hasOwnProperty' : 'a' ,
185
+ expect ( update ( { } , { hasOwnProperty : { $set : 'a' } } ) ) . toEqual ( {
186
+ hasOwnProperty : 'a' ,
183
187
} ) ;
184
188
} ) ;
185
189
} ) ;
0 commit comments