1- import { describe , expect , it , vi } from 'vitest' ;
1+ import { beforeEach , describe , expect , it , vi } from 'vitest' ;
22import { callCreateDocumentApi } from './uploadPageController' ;
33import * as api from '../../utils/api' ;
44
@@ -28,10 +28,12 @@ class MockFileReader {
2828 }
2929}
3030
31- // allow `new FileReader()` to work even in a node (test) environment
32- vi . stubGlobal ( 'FileReader' , MockFileReader ) ;
33-
3431describe ( 'callCreateDocumentApi' , ( ) => {
32+ beforeEach ( ( ) => {
33+ // allow `new FileReader()` to work even in a node (test) environment
34+ vi . stubGlobal ( 'FileReader' , MockFileReader ) ;
35+ } ) ;
36+
3537 const mockAuthorizedFetch = api . authorizedFetch as ReturnType < typeof vi . fn > ;
3638
3739 // Create a mock File object
@@ -165,10 +167,8 @@ describe('callCreateDocumentApi', () => {
165167
166168 it ( 'should handle file reading errors' , async ( ) => {
167169 // Set the MockFileReader to fail
168- const originalFileReader = globalThis . FileReader ;
169170 const mockFileReaderInstance = new MockFileReader ( ) ;
170171 mockFileReaderInstance . readSuccess = false ;
171-
172172 // Override the FileReader constructor to return our configured instance
173173 vi . stubGlobal ( 'FileReader' , function ( ) {
174174 return mockFileReaderInstance ;
@@ -181,9 +181,6 @@ describe('callCreateDocumentApi', () => {
181181 failure : 'other' ,
182182 responseData : undefined ,
183183 } ) ;
184-
185- // Restore the original FileReader
186- vi . stubGlobal ( 'FileReader' , originalFileReader ) ;
187184 } ) ;
188185
189186 it ( 'should handle empty files' , async ( ) => {
0 commit comments