1- import { render , screen , fireEvent } from "@testing-library/react" ;
1+ import { render , screen , fireEvent , act } from "@testing-library/react" ;
22import { vi } from "vitest" ;
33import UploadRecipe from "../UploadRecipe" ;
44
@@ -27,7 +27,12 @@ describe("UploadRecipe Component", () => {
2727 expect ( screen . getByLabelText ( "Upload Recipe PDF" ) ) . toBeInTheDocument ( ) ;
2828 } ) ;
2929
30- it ( "shows uploading state when file is selected" , ( ) => {
30+ it ( "shows uploading state when file is selected" , async ( ) => {
31+ mockFetch . mockResolvedValueOnce ( {
32+ ok : true ,
33+ json : async ( ) => ( { } ) ,
34+ } ) ;
35+
3136 render ( < UploadRecipe /> ) ;
3237
3338 const fileInput = screen . getByLabelText (
@@ -37,7 +42,9 @@ describe("UploadRecipe Component", () => {
3742 type : "application/pdf" ,
3843 } ) ;
3944
40- fireEvent . change ( fileInput ! , { target : { files : [ file ] } } ) ;
45+ await act ( async ( ) => {
46+ fireEvent . change ( fileInput ! , { target : { files : [ file ] } } ) ;
47+ } ) ;
4148
4249 // Check that fetch was called
4350 expect ( mockFetch ) . toHaveBeenCalledWith ( "/api/genai/upload" , {
0 commit comments