Skip to content

FAQ

  • 设置日期与计时器与vitest
  • Vue 警告: 设置Props失败

设置日期与计时器与vitest

Vue的调度器取决于系统时间。确保在调用vi.setSystemTime之后挂载组件,因为Vue取决于它的副作用。在调用vi.setSystemTime之前安装组件可能会导致反应中断。

看到vuejs / test-utils # 2074

Vue 警告: 设置Props失败

bash
[Vue warn]: Failed setting prop "prefix" on <component-stub>: value foo is invalid.
TypeError: Cannot set property prefix of #<Element> which has only a getter
[Vue warn]: Failed setting prop "prefix" on <component-stub>: value foo is invalid.
TypeError: Cannot set property prefix of #<Element> which has only a getter

如果您使用的是与Element共享属性名的shallowMountstub,则会显示此警告。

Element共享的通用属性名:

  • attributes
  • children
  • prefix

查看 https://developer.mozilla.org/en-US/docs/Web/API/Element

可能的解决方案

  • 使用mount而不是shallowMount来渲染无存根
  • 通过模拟console.warn来忽略警告
  • 重命名该道具以避免与元素属性冲突