~/talk

Vue Router, Hoisting Mocks and Unit Test Spaghetti

Talkat Connect.Tech 2024 · 2024-11-18..11-20· [vue, testing]
links:none on file
slides:none on file

Vest (vtest) hoists mocks and constants so repeated runs with describe.each produce corrupted state and a mysteriously failing second pass, especially when Vue Router is mocked and a component mutates the URL. Reproduce and fix: swap the mock for the real Vue Router initialized in abstract mode and reset router.query/params, deep clone inputs with cloneDeep to avoid shared-object mutation, attach spies to component methods before mount to catch mounted/created calls, and stub window.location/matchMedia or initialize real API client instances when Vuex getters return mocked plain objects — these fixes restore deterministic tests.

AI-written summary · about

  1. 0:00Introduction and context
  2. 2:54Vue Router mock issues
  3. 7:50describe.each pitfalls
  4. 14:13Lifecycle hook mocking
  5. 17:05Mocking window object
  6. 21:40API client initialization
  7. 24:48Key takeaways summary
  8. 26:42Q&A session
~/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.