@@ -110,6 +110,28 @@ describe('update', function() {
110
110
} ) ;
111
111
} ) ;
112
112
113
+ describe ( '$unset' , function ( ) {
114
+ it ( 'unsets' , function ( ) {
115
+ expect ( update ( { a : 'b' } , { $unset : [ 'a' ] } ) . a ) . toBe ( undefined ) ;
116
+ } ) ;
117
+ it ( 'removes the key from the object' , function ( ) {
118
+ var removed = update ( { a : 'b' } , { $unset : [ 'a' ] } ) ;
119
+ expect ( 'a' in removed ) . toBe ( false ) ;
120
+ } ) ;
121
+ it ( 'does not remove keys from the inherited properties' , function ( ) {
122
+ function Parent ( ) { this . foo = 'Parent' ; }
123
+ function Child ( ) { }
124
+ Child . prototype = new Parent ( )
125
+ var child = new Child ( ) ;
126
+ expect ( update ( child , { $unset : [ 'foo' ] } ) . foo ) . toEqual ( 'Parent' ) ;
127
+ } ) ;
128
+ it ( 'keeps reference equality when possible' , function ( ) {
129
+ var original = { a : 1 } ;
130
+ expect ( update ( original , { $unset : [ 'b' ] } ) ) . toBe ( original ) ;
131
+ expect ( update ( original , { $unset : [ 'a' ] } ) ) . toNotBe ( original ) ;
132
+ } ) ;
133
+ } ) ;
134
+
113
135
describe ( '$apply' , function ( ) {
114
136
var applier = function ( node ) {
115
137
return { v : node . v * 2 } ;
@@ -233,6 +255,13 @@ describe('update', function() {
233
255
} ) ;
234
256
} ) ;
235
257
258
+ it ( 'should reject non arrays from $unset' , function ( ) {
259
+ expect ( update . bind ( null , { a : 'b' } , { $unset : 'a' } ) ) . toThrow (
260
+ 'update(): expected spec of $unset to be an array; got a. ' +
261
+ 'Did you forget to wrap the key(s) in an array?'
262
+ ) ;
263
+ } ) ;
264
+
236
265
it ( 'should require a plain object spec containing command(s)' , function ( ) {
237
266
var specs = [
238
267
null ,
@@ -244,7 +273,7 @@ describe('update', function() {
244
273
expect ( update . bind ( null , { a : 'b' } , spec ) ) . toThrow (
245
274
'update(): You provided an invalid spec to update(). The spec ' +
246
275
'and every included key path must be plain objects containing one ' +
247
- 'of the following commands: $push, $unshift, $splice, $set, ' +
276
+ 'of the following commands: $push, $unshift, $splice, $set, $unset, ' +
248
277
'$merge, $apply.'
249
278
) ;
250
279
} ) ;
0 commit comments