File tree Expand file tree Collapse file tree 1 file changed +45
-7
lines changed Expand file tree Collapse file tree 1 file changed +45
-7
lines changed Original file line number Diff line number Diff line change @@ -37,9 +37,9 @@ test('renders with color modes', () => {
37
37
modes : {
38
38
dark : {
39
39
text : 'white' ,
40
- }
41
- }
42
- }
40
+ } ,
41
+ } ,
42
+ } ,
43
43
} } >
44
44
< Mode />
45
45
</ ThemeProvider >
@@ -64,8 +64,8 @@ test('renders with initial color mode name', () => {
64
64
colors : {
65
65
modes : {
66
66
dark : { } ,
67
- }
68
- }
67
+ } ,
68
+ } ,
69
69
} } >
70
70
< Mode />
71
71
</ ThemeProvider >
@@ -212,8 +212,8 @@ test('inherits color mode state from parent context', () => {
212
212
colors : {
213
213
modes : {
214
214
dark : { } ,
215
- }
216
- }
215
+ } ,
216
+ } ,
217
217
} } >
218
218
< ThemeProvider
219
219
theme = { {
@@ -518,3 +518,41 @@ test('raw color values are passed to theme-ui context when custom properties are
518
518
)
519
519
expect ( color ) . toBe ( 'tomato' )
520
520
} )
521
+
522
+ test ( 'warns when localStorage is disabled' , ( ) => {
523
+ const originalWindow = window
524
+
525
+ const mockWindow = new Proxy ( window , {
526
+ get : ( obj , prop ) => {
527
+ if ( prop === 'localStorage' ) {
528
+ throw 'SecurityError: The operation is insecure.'
529
+ } else {
530
+ return obj [ prop ]
531
+ }
532
+ } ,
533
+ } )
534
+
535
+ Object . defineProperty ( global , 'window' , {
536
+ value : mockWindow ,
537
+ writable : true ,
538
+ } )
539
+
540
+ let mode
541
+ const Consumer = props => {
542
+ const [ colorMode ] = useColorMode ( )
543
+ mode = colorMode
544
+ return false
545
+ }
546
+
547
+ render (
548
+ < ThemeProvider >
549
+ < Consumer />
550
+ </ ThemeProvider >
551
+ )
552
+ expect ( mode ) . toBe ( 'default' )
553
+
554
+ Object . defineProperty ( global , 'window' , {
555
+ value : originalWindow ,
556
+ writable : true ,
557
+ } )
558
+ } )
You can’t perform that action at this time.
0 commit comments