~/talk

The Ins and Outs of Module Mocking in Vitest

Talkat Vuejs Amsterdam 2024 · 2024-02-28..02-29· [testing]
links:none on file
slides:none on file

Vitest explains how module mocking actually works: it uses vit-node and a custom runner to transform static imports into dynamic SSR imports and replace named exports with getters, registers mocks before imports by hoisting mock calls, and intercepts imports to ensure mock factories or __mocks__ files load instead of originals. It documents edge cases: top-level variables are unavailable, partial-module overrides return a new module namespace (so local internal calls keep originals), and virtual modules need config entries; examples include working and failing snippets and practical fixes.

AI-written summary · about

  1. 0:00Module mocking intro
  2. 2:44How Vitest loads modules
  3. 5:14Fixing mocking mistakes
  4. 8:51Runtime import interception
  5. 11:22Mocked module registration
  6. 13:08Vitest module future
  7. 15:15Mocking edge cases
  8. 16:43Partial module mocking
  9. 20:22Virtual modules in Vitest
  10. 22:00Q&A
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.