1
- describe ( 'Tests functionality of the localStorage module' , function ( ) {
2
- beforeEach ( module ( 'LocalStorageModule' , function ( localStorageServiceProvider ) {
3
- p = localStorageServiceProvider ;
4
- } ) ) ;
5
- var ls , store = [ ] ;
6
- beforeEach ( inject ( function ( _localStorageService_ ) {
7
- ls = _localStorageService_ ;
8
- spyOn ( ls , 'get' ) . andCallFake ( function ( key ) {
9
- if ( store [ key ] . charAt ( 0 ) === "{" || store [ key ] . charAt ( 0 ) === "[" ) {
10
- return angular . fromJson ( store [ key ] ) ;
11
- } else {
12
- return store [ key ] ;
13
- }
14
- } ) ;
15
-
16
- spyOn ( ls , 'set' ) . andCallFake ( function ( key , val ) {
17
- if ( angular . isObject ( val ) || angular . isArray ( val ) ) {
18
- val = angular . toJson ( val ) ;
19
- }
20
- if ( angular . isNumber ( val ) ) {
21
- val = val . toString ( ) ;
22
- }
23
- return store [ key ] = val ;
24
- } ) ;
25
-
26
- spyOn ( ls , 'clearAll' ) . andCallFake ( function ( ) {
27
- store = { } ;
28
- return store ;
29
- } ) ;
30
- } ) ) ;
31
-
32
- it ( "Should add a value to my local storage" , function ( ) {
33
- var n = 234 ;
34
- ls . set ( 'test' , n ) ;
35
- //Since localStorage makes the value a string, we look for the '234' and not 234
36
- expect ( ls . get ( 'test' ) ) . toBe ( '234' ) ;
37
-
38
- var obj = { key : 'val' } ;
39
- ls . set ( 'object' , obj ) ;
40
- var res = ls . get ( 'object' ) ;
41
- expect ( res . key ) . toBe ( 'val' ) ;
1
+ 'use strict' ;
42
2
3
+ describe ( 'Tests functionality of the localStorage module' , function ( ) {
4
+ var ls , p , store = [ ] ;
5
+
6
+ beforeEach ( module ( 'LocalStorageModule' , function ( localStorageServiceProvider ) {
7
+ p = localStorageServiceProvider ;
8
+ } ) ) ;
9
+
10
+ beforeEach ( inject ( function ( _localStorageService_ ) {
11
+ ls = _localStorageService_ ;
12
+ spyOn ( ls , 'get' ) . andCallFake ( function ( key ) {
13
+ if ( store [ key ] . charAt ( 0 ) === '{' || store [ key ] . charAt ( 0 ) === '[' ) {
14
+ return angular . fromJson ( store [ key ] ) ;
15
+ } else {
16
+ return store [ key ] ;
17
+ }
43
18
} ) ;
44
19
45
- it ( 'Should allow me to set a prefix' , function ( ) {
46
- p . setPrefix ( "myPref" ) ;
47
- expect ( p . prefix ) . toBe ( "myPref" ) ;
20
+ spyOn ( ls , 'set' ) . andCallFake ( function ( key , val ) {
21
+ if ( angular . isObject ( val ) || angular . isArray ( val ) ) {
22
+ val = angular . toJson ( val ) ;
23
+ }
24
+ if ( angular . isNumber ( val ) ) {
25
+ val = val . toString ( ) ;
26
+ }
27
+ store [ key ] = val ;
28
+ return store [ key ] ;
48
29
} ) ;
49
30
50
- it ( 'Should allow me to set the cookie values' , function ( ) {
51
- p . setStorageCookie ( 60 , '/path' ) ;
52
- expect ( p . cookie . expiry ) . toBe ( 60 ) ;
53
- expect ( p . cookie . path ) . toBe ( '/path' ) ;
31
+ spyOn ( ls , 'clearAll' ) . andCallFake ( function ( ) {
32
+ store = { } ;
33
+ return store ;
54
34
} ) ;
35
+ } ) ) ;
36
+
37
+ it ( 'Should add a value to my local storage' , function ( ) {
38
+ var n = 234 ;
39
+ ls . set ( 'test' , n ) ;
40
+ //Since localStorage makes the value a string, we look for the '234' and not 234
41
+ expect ( ls . get ( 'test' ) ) . toBe ( '234' ) ;
42
+
43
+ var obj = { key : 'val' } ;
44
+ ls . set ( 'object' , obj ) ;
45
+ var res = ls . get ( 'object' ) ;
46
+ expect ( res . key ) . toBe ( 'val' ) ;
47
+ } ) ;
48
+
49
+ it ( 'Should allow me to set a prefix' , function ( ) {
50
+ p . setPrefix ( 'myPref' ) ;
51
+ expect ( p . prefix ) . toBe ( 'myPref' ) ;
52
+ } ) ;
53
+
54
+ it ( 'Should allow me to set the cookie values' , function ( ) {
55
+ p . setStorageCookie ( 60 , '/path' ) ;
56
+ expect ( p . cookie . expiry ) . toBe ( 60 ) ;
57
+ expect ( p . cookie . path ) . toBe ( '/path' ) ;
58
+ } ) ;
55
59
} ) ;
0 commit comments