vitest.setup.ts 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. Object.defineProperty(document, "getSelection", {
  2. value: () => ({
  3. removeAllRanges: () => {},
  4. addRange: () => {},
  5. rangeCount: 0,
  6. }),
  7. writable: true,
  8. })
  9. // ── defineModel / useModel local mode quirk ──
  10. //
  11. // In Vue 3.5, useModel (compiled from defineModel) enters "local mode"
  12. // when no onUpdate:X listener is provided by the parent. The local ref
  13. // initialises as undefined, NOT from the prop value.
  14. //
  15. // VTU's shallowMount(Comp, { props: { content: "Hello" } }) sets the
  16. // prop but does NOT supply a synthetic onUpdate:content listener, so
  17. // useModel enters local mode and content.value is undefined on the
  18. // first tick. Any immediate watcher on content.value fires with
  19. // undefined instead of "Hello".
  20. //
  21. // Two solutions (both applied to this codebase):
  22. //
  23. // 1. In tests: provide `"onUpdate:content": vi.fn()` alongside the
  24. // content prop to keep useModel in "connected" mode.
  25. //
  26. // 2. In Editor.vue: watch `content.value ?? props.content` so the
  27. // immediate fallback reads from the raw prop when useModel is in
  28. // local mode.
  29. //
  30. // Reference: https://github.com/vuejs/core/issues/12005