Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(zh): 更新 Vitest 模拟日期和计时器的说明 #2578

Merged
merged 2 commits into from
Jan 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions docs/zh/guide/faq/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

[[toc]]

## 使用 Vitest 模拟日期和定时器
## 使用 Vitest 模拟日期和计时器

Vue 的调度器依赖于系统时间。在调用 `vi.setSystemTime` 之后再挂载组件,因为 Vue 依赖于其副作用。在调用 `vi.setSystemTime` 之前挂载组件可能会导致响应性中断
Vue 的调度器依赖于系统时间。请务必在调用 `vi.setSystemTime` 后再挂载组件,因为 Vue 依赖于其副作用。在调用 `vi.setSystemTime` 之前挂载组件可能会破坏其响应性

请参见 [vuejs/test-utils#2074](https://github.com/vuejs/test-utils/issues/2074)。
请查看 [vuejs/test-utils#2074](https://github.com/vuejs/test-utils/issues/2074)。

## Vue warn: Failed setting prop

Expand All @@ -15,18 +15,17 @@ Vue 的调度器依赖于系统时间。在调用 `vi.setSystemTime` 之后再
TypeError: Cannot set property prefix of #<Element> which has only a getter
```

如果你使用 `shallowMount` 或 `stubs`,并且使用了与 [`Element`](https://developer.mozilla.org/en-US/docs/Web/API/Element) 共享的属性名称,将会显示此警告
当您使用 `shallowMount` 或具有与 [`Element`](https://developer.mozilla.org/en-US/docs/Web/API/Element) 共享的属性名称的 `stubs` 时,会显示此警告

与 `Element` 共享的常见属性名称:
* `attributes`
* `children`
* `prefix`

- `attributes`
- `children`
- `prefix`

请参见:https://developer.mozilla.org/en-US/docs/Web/API/Element
请参阅:https://developer.mozilla.org/zh-CN/docs/Web/API/Element

**可能的解决方案**

1. 使用 `mount` 而不是 `shallowMount` 来渲染而不使用桩
1. 使用 `mount` 而不是 `shallowMount` 进行不带存根的渲染
2. 通过模拟 `console.warn` 来忽略警告
3. 重命名 prop,以避免与 `Element` 属性冲突
Loading