You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: guide/migration.md
+13-15
Original file line number
Diff line number
Diff line change
@@ -56,7 +56,7 @@ export default defineConfig({
56
56
57
57
### `spy.mockReset` Now Restores the Original Implementation
58
58
59
-
There was no good way to reset the spy to the original implementation without reaplying the spy. Now, `spy.mockReset`will reset the implementation function to the original one instead of a fake noop.
### `vi.spyOn` Reuses Mock if Method is Already Mocked
77
77
78
-
Previously, Vitest would always assign a new spy when spying on an object. This caused errors with `mockRestore`because it would restore the spy to the previous spy instead of the original function:
Vitest no longer provides default `fakeTimers.toFake`options. Now, Vitest will mock any timer-related API if it is available (except `nextTick`). Namely, `performance.now()`is now mocked when `vi.useFakeTimers` is called.
Vitest now checks more properties when comparing errors via `toEqual`or`toThrowError`. Vitest now compares `name`, `message`, `cause`and`AggregateError.errors`. For `Error.cause`, the comparison is done asymmetrically:
In addition to more properties check, Vitest now compares error prototypes. For example, if `TypeError` was thrown, the equality check should reference `TypeError`, not `Error`:
### `Custom` Type is Deprecated <Badgetype="danger">API</Badge> {#custom-type-is-deprecated}
133
133
@@ -152,9 +152,9 @@ import {
152
152
153
153
### Changes to the Snapshot API <Badgetype="danger">API</Badge> {#changes-to-the-snapshot-api}
154
154
155
-
The public Snapshot API in `@vitest/snapshot`was changed to support multiple states within a single run. See PR for more details: [#6817](https://github.com/vitest-dev/vitest/pull/6817)
155
+
`@vitest/snapshot`中的公共 Snapshot API 已更改,以支持在单次运行中处理多个状态。更多详情请参见 PR:[#6817](https://github.com/vitest-dev/vitest/pull/6817)。
156
156
157
-
Note that this changes only affect developers using the Snapshot API directly. There were no changes to `.toMatchSnapshot` API.
157
+
请注意,这些更改仅影响直接使用 Snapshot API 的开发者。`.toMatchSnapshot` API 没有任何变化。
158
158
159
159
### Changes to `resolveConfig` Type Signature <Badgetype="danger">API</Badge> {#changes-to-resolveconfig-type-signature}
160
160
@@ -164,11 +164,11 @@ Note that this changes only affect developers using the Snapshot API directly. T
164
164
165
165
### Cleaned up `vitest/reporters` types <Badgetype="danger">API</Badge> {#cleaned-up-vitest-reporters-types}
166
166
167
-
The `vitest/reporters`entrypoint now only exports reporters implementations and options types. If you need access to `TestCase`/`TestSuite`and other task related types, import them additionally from `vitest/node`.
Previously Vitest resolved `mock.results`values if the function returned a Promise. Now there is a separate [`mock.settledResults`](/api/mock#mock-settledresults)property that populates only when the returned Promise is resolved or rejected.
With this change, we also introduce new [`toHaveResolved*`](/api/expect#tohaveresolved)matchers similar to `toHaveReturned` to make migration easier if you used `toHaveReturned` before:
We removed a lot of configuration options to make it easier to configure the runner to your needs. Please, have a look at migration examples if you rely on `--threads` or other related flags.
The UI is interactive and requires a running Vite server, so make sure to run Vitest in `watch`mode (the default). Alternatively, you can generate a static HTML report that looks identical to the Vitest UI by specifying `html`in config's `reporters` option.
22
+
UI 是交互式的,需要一个正在运行的 Vite 服务器,因此请确保在 `watch`模式(默认模式)下运行 Vitest。或者,你可以通过在配置的 `reporters` 选项中指定 `html`来生成一个与 Vitest UI 完全相同的静态 HTML 报告。
0 commit comments