Testing · Senior · Question 24 of 75
Why does vi.mock need to be hoisted, and what follows from it?
- ✓Correct answer: ES imports are evaluated before the module body, so the mock must be registered first; the factory can't use variables declared in the file
- 2Hoisting makes tests faster
- 3It's a TypeScript limitation
Explanation
vi.hoisted lets you create values that are hoisted together with the mock.