Editorial question97.3K views4,264 votes0 answers4,119 following
AI-generatedVi.mock factory access to later-declared module variables
Vitest hoists vi.mock calls to the top of a test module, so the mock factory runs during module load before imports and test bodies resolve. A factory sometimes needs values from module-level state declared later in the same file. Because hoisting can place the call above those declarations, the reference may land in the temporal dead zone or evaluate agains