Appearance
常见问题
¥FAQ
[[目录]]
¥[[toc]]
使用 Vitest 模拟日期和计时器
¥Mocking Dates and Timers with Vitest
Vue 的调度程序取决于系统时间。确保在调用 vi.setSystemTime 之后挂载组件,因为 Vue 依赖于它的副作用。在调用 vi.setSystemTime 之前挂载组件可能会导致反应性中断。
¥Vue's scheduler depends on the system time. Make sure to mount components after calling vi.setSystemTime, since Vue depends on its side effects. Mounting components before calling vi.setSystemTime may cause breaks in reactivity.
参见 vuejs/测试工具#2074。
¥See vuejs/test-utils#2074.
Vue 警告:设置属性失败
¥Vue warn: Failed setting prop
[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如果你使用 shallowMount 或 stubs 的属性名称与 Element 共享,则会显示此警告。
¥This warning is shown in case you are using shallowMount or stubs with a property name that is shared with Element.
与 Element 共享的公共属性名称:
¥Common property names that are shared with Element:
attributeschildrenprefix
看:https://web.nodejs.cn/en-US/docs/Web/API/Element
¥See: https://web.nodejs.cn/en-US/docs/Web/API/Element
可能的解决方案
¥Possible solutions
使用
mount而不是shallowMount进行无存根渲染¥Use
mountinstead ofshallowMountto render without stubs通过模拟
console.warn来忽略警告¥Ignore the warning by mocking
console.warn重命名属性以免与
Element属性冲突¥Rename the prop to not clash with
Elementproperties