@@ -6,6 +6,8 @@ beforeEach(() => {
6
6
sessionStorage . clear ( )
7
7
} )
8
8
9
+ // Note- lodash "once" is mocked to simulate each function being run in a new context.
10
+
9
11
describe ( 'loadSessionState()' , ( ) => {
10
12
it ( 'loads session state from localStorage and sessionStorage' , ( ) => {
11
13
const advisorToken = 'foo'
@@ -23,6 +25,19 @@ describe('loadSessionState()', () => {
23
25
client : { token : clientToken , persist : clientPersist }
24
26
} )
25
27
} )
28
+ describe ( 'with prohibited localStorage' , ( ) => {
29
+ beforeAll ( ( ) => {
30
+ saveSessionState ( { advisor : { token : 'foo' , persist : true } } )
31
+ window . getItem = Storage . prototype . getItem
32
+ Storage . prototype . getItem = ( ) => { throw new Error ( 'No access.' ) }
33
+ } )
34
+ it ( 'fails gracefully' , ( ) => {
35
+ expect ( ( ) => loadSessionState ( ) ) . not . toThrow ( )
36
+ } )
37
+ afterAll ( ( ) => {
38
+ Storage . prototype . getItem = window . getItem
39
+ } )
40
+ } )
26
41
} )
27
42
28
43
describe ( 'saveSessionState()' , ( ) => {
@@ -41,6 +56,18 @@ describe('saveSessionState()', () => {
41
56
expect ( sessionStorage . getItem ( 'redux-sessions:token:client' ) ) . toEqual ( clientToken )
42
57
expect ( sessionStorage . getItem ( 'redux-sessions:persist:client' ) ) . toEqual ( null )
43
58
} )
59
+ describe ( 'with prohibited localStorage' , ( ) => {
60
+ beforeAll ( ( ) => {
61
+ window . setItem = Storage . prototype . setItem
62
+ Storage . prototype . setItem = ( ) => { throw new Error ( 'No access.' ) }
63
+ } )
64
+ it ( 'fails gracefully' , ( ) => {
65
+ expect ( ( ) => saveSessionState ( { advisor : { token : 'foo' , persist : true } } ) ) . not . toThrow ( )
66
+ } )
67
+ afterAll ( ( ) => {
68
+ Storage . prototype . setItem = window . setItem
69
+ } )
70
+ } )
44
71
} )
45
72
46
73
test ( 'persistence helpers are reciprocal' , ( ) => {
0 commit comments