File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import { afterEach , beforeEach } from 'vitest' ;
1+ import { afterAll , beforeEach , vi } from 'vitest' ;
2+
3+ const localStorageMock : Storage = ( ( ) => {
4+ const store = new Map < string , string > ( ) ;
5+
6+ return {
7+ getItem : ( key : string ) => store . get ( key ) ?? null ,
8+ setItem : ( key : string , value : string ) => {
9+ store . set ( key , value ) ;
10+ } ,
11+ removeItem : ( key : string ) => {
12+ store . delete ( key ) ;
13+ } ,
14+ clear : ( ) => {
15+ store . clear ( ) ;
16+ } ,
17+ get length ( ) {
18+ return store . size ;
19+ } ,
20+ key : ( index : number ) => Array . from ( store . keys ( ) ) [ index ] ?? null ,
21+ } ;
22+ } ) ( ) ;
23+
24+ vi . stubGlobal ( 'localStorage' , localStorageMock ) ;
225
326beforeEach ( ( ) => {
4- // Reserved for shared test setup.
27+ localStorage . clear ( ) ;
528} ) ;
629
7- afterEach ( ( ) => {
8- // Reserved for shared test cleanup.
9- } ) ;
30+ afterAll ( ( ) => {
31+ vi . unstubAllGlobals ( ) ;
32+ } ) ;
You can’t perform that action at this time.
0 commit comments