@@ -66,11 +66,11 @@ describe('Module: LocalForageModule', function() {
66
66
67
67
$localForage . getItem ( 'this key is unknown' ) . then ( function ( value ) {
68
68
stopDigests ( interval ) ;
69
- expect ( value ) . toBeNull ( )
69
+ expect ( value ) . toBeNull ( ) ;
70
70
done ( ) ;
71
71
} , done ) ;
72
72
} ) ;
73
-
73
+
74
74
it ( 'setItem and getItem should work' , function ( done ) {
75
75
var interval = triggerDigests ( ) ;
76
76
@@ -85,7 +85,7 @@ describe('Module: LocalForageModule', function() {
85
85
86
86
} , done ) ;
87
87
} ) ;
88
-
88
+
89
89
it ( 'setItem and getItem should work with an array of keys' , function ( done ) {
90
90
var interval = triggerDigests ( ) ,
91
91
values = [ 'Olivier Combe' , 'AngularJs' , 'Open Source' ] ;
@@ -326,6 +326,40 @@ describe('Module: LocalForageModule', function() {
326
326
$localForage . setItem ( ) ;
327
327
} ) . toThrowError ( 'You must define a key to set' ) ;
328
328
} ) ;
329
+
330
+ describe ( "bind" , function ( ) {
331
+ var $scope , $q ;
332
+
333
+ beforeEach ( inject ( function ( $rootScope , _$q_ ) {
334
+ $scope = $rootScope ;
335
+ $q = _$q_ ;
336
+ } ) ) ;
337
+
338
+ it ( ' should use the default stored value if nothing has been previously stored' , function ( done ) {
339
+ // Check different types of items.
340
+ var testItems = [ { foo : 'bar' } , [ "cat" , "dog" , "pidgeon" ] , 123 , 0 , true , false ]
341
+ var promises = [ ] ;
342
+ // Store all the items, deleting old values
343
+ for ( var i = 0 ; i < testItems . length ; i ++ ) {
344
+ $localForage . removeItem ( 'item' + i ) ;
345
+ var item = testItems [ i ] ;
346
+ promises . push (
347
+ $localForage . bind ( $scope , {
348
+ key : 'item' + i ,
349
+ defaultValue : item ,
350
+ } )
351
+ ) ;
352
+ }
353
+ // After all promises have been resolved, check the items are what we expect them to be.
354
+ $q . all ( promises ) . then ( function ( ) {
355
+ for ( var i = 0 ; i < testItems . length ; i ++ ) {
356
+ expect ( $scope [ 'item' + i ] ) . toBe ( testItems [ i ] ) ;
357
+ }
358
+ } ) ;
359
+ done ( ) ;
360
+ } ) ;
361
+
362
+ } ) ;
329
363
330
364
describe ( "iterate" , function ( ) {
331
365
var interval ;
0 commit comments