@@ -8,15 +8,12 @@ const ORIGINAL_ENV = process.env.NODE_ENV;
88
99describe ( 'storage utils' , ( ) => {
1010 function ensureWindowWithLocalStorage ( ) {
11- // Ensure a Window-like global for Node environment
1211 if ( typeof window === 'undefined' ) {
1312 Object . defineProperty ( globalThis , 'window' , {
14- // unknown avoids explicit any; cast to Window shape for tests
1513 value : { } as unknown as Window & typeof globalThis ,
1614 configurable : true
1715 } ) ;
1816 }
19- // Polyfill localStorage if missing
2017 if ( ! ( 'localStorage' in window ) ) {
2118 const store = new Map < string , string > ( ) ;
2219 Object . defineProperty ( window , 'localStorage' , {
@@ -35,7 +32,7 @@ describe('storage utils', () => {
3532 }
3633
3734 beforeEach ( ( ) => {
38- // Ensure clean slate
35+ ensureWindowWithLocalStorage ( ) ;
3936 try {
4037 window . localStorage . removeItem ( KEY ) ;
4138 } catch {
@@ -53,14 +50,12 @@ describe('storage utils', () => {
5350 } ) ;
5451
5552 it ( 'SSR/test guard disables storage (returns fallback in test env)' , ( ) => {
56- // In vitest, NODE_ENV is "test" by default. Verify guard path returns fallback.
5753 window . localStorage . setItem ( KEY , JSON . stringify ( { value : 123 } ) ) ;
5854 const result = loadFromStorage ( KEY , { value : 999 } ) ;
5955 expect ( result ) . toEqual ( { value : 999 } ) ;
6056 } ) ;
6157
6258 it ( 'Malformed JSON returns fallback' , ( ) => {
63- // Enable storage access by switching to a non-test env for this test
6459 process . env . NODE_ENV = 'development' ;
6560 ensureWindowWithLocalStorage ( ) ;
6661 window . localStorage . setItem ( KEY , '{not json' ) ;
0 commit comments