diff --git a/.vitepress/components.d.ts b/.vitepress/components.d.ts
index b509b572..1d997988 100644
--- a/.vitepress/components.d.ts
+++ b/.vitepress/components.d.ts
@@ -1,10 +1,10 @@
/* eslint-disable */
+/* prettier-ignore */
// @ts-nocheck
// Generated by unplugin-vue-components
// Read more: https://github.com/vuejs/core/pull/3399
export {}
-/* prettier-ignore */
declare module 'vue' {
export interface GlobalComponents {
Contributors: typeof import('./components/Contributors.vue')['default']
diff --git a/.vitepress/components/FeaturesList.vue b/.vitepress/components/FeaturesList.vue
index c6a4359b..fadf20b1 100644
--- a/.vitepress/components/FeaturesList.vue
+++ b/.vitepress/components/FeaturesList.vue
@@ -86,7 +86,6 @@
>expect-type
进行类型测试
- 支持分片
diff --git a/.vitepress/config.ts b/.vitepress/config.ts
index 0fdf8e4e..1cf751b5 100644
--- a/.vitepress/config.ts
+++ b/.vitepress/config.ts
@@ -32,13 +32,13 @@ export default () => {
en: {
label: 'English',
lang: 'en',
- link: 'https://vitest.dev/',
+ link: 'https://v1.vitest.dev/',
},
},
head: [
['meta', { name: 'theme-color', content: '#729b1a' }],
- ['link', { rel: 'icon', href: '/favicon.ico', sizes: '48x48' }],
- ['link', { rel: 'icon', href: '/logo.svg', sizes: 'any', type: 'image/svg+xml' }],
+ ['link', { rel: 'icon', href: '/favicon.ico', sizes: 'any' }],
+ ['link', { rel: 'icon', href: '/logo.svg', type: 'image/svg+xml' }],
['meta', { name: 'author', content: `${teamMembers.map(c => c.name).join(', ')} and ${vitestName} contributors` }],
['meta', { name: 'keywords', content: 'vitest, vite, test, coverage, snapshot, react, vue, preact, svelte, solid, lit, marko, ruby, cypress, puppeteer, jsdom, happy-dom, test-runner, jest, typescript, esm, tinypool, tinyspy, node' }],
['meta', { property: 'og:title', content: vitestName }],
@@ -69,7 +69,7 @@ export default () => {
logo: '/logo.svg',
editLink: {
- pattern: 'https://github.com/vitest-dev/docs-cn/tree/dev/:path',
+ pattern: 'https://github.com/vitest-dev/docs-cn/tree/v1/:path',
text: '为此页提供修改建议',
},
@@ -123,7 +123,7 @@ export default () => {
text: '社区指南',
link: contributing,
},
- ]
+ ],
},
{
items: [
@@ -135,10 +135,6 @@ export default () => {
text: 'v0.x',
link: 'https://v0.vitest.dev/',
},
- {
- text: 'v1.x',
- link: 'https://v1.vitest.dev/',
- },
],
},
],
@@ -173,12 +169,12 @@ export default () => {
],
},
],
- '/': [
+ '/guide/': [
{
text: '指南',
items: [
{
- text: '简介',
+ text: '为什么是 Vitest?',
link: '/guide/why',
},
{
@@ -222,45 +218,12 @@ export default () => {
link: '/guide/testing-types',
},
{
- text: 'Vitest UI',
+ text: 'UI 模式',
link: '/guide/ui',
},
{
text: '浏览器模式',
- link: '/guide/browser/',
- collapsed: false,
- items: [
- {
- text: 'Assertion API',
- link: '/guide/browser/assertion-api',
- docFooterText: 'Assertion API | Browser Mode',
- },
- {
- text: 'Retry-ability',
- link: '/guide/browser/retry-ability',
- docFooterText: 'Retry-ability | Browser Mode',
- },
- {
- text: 'Context',
- link: '/guide/browser/context',
- docFooterText: 'Context | Browser Mode',
- },
- {
- text: 'Interactivity API',
- link: '/guide/browser/interactivity-api',
- docFooterText: 'Interactivity API | Browser Mode',
- },
- {
- text: 'Commands',
- link: '/guide/browser/commands',
- docFooterText: 'Commands | Browser Mode',
- },
- {
- text: 'Examples',
- link: '/guide/browser/examples',
- docFooterText: 'Examples | Browser Mode',
- },
- ],
+ link: '/guide/browser',
},
{
text: '源码内联测试',
@@ -287,7 +250,7 @@ export default () => {
link: '/guide/debugging',
},
{
- text: '与其他测试框架对比',
+ text: '测试框架比较',
link: '/guide/comparisons',
},
{
@@ -304,6 +267,8 @@ export default () => {
},
],
},
+ ],
+ '/api/': [
{
text: 'API',
items: [
@@ -337,6 +302,8 @@ export default () => {
},
],
},
+ ],
+ '/config/': [
{
text: '配置',
items: [
diff --git a/advanced/api.md b/advanced/api.md
index f743f3e4..12dc4e70 100644
--- a/advanced/api.md
+++ b/advanced/api.md
@@ -4,7 +4,7 @@
Vitest 暴露了实验性的私有 API。由于可能不遵循语义化版本规范(SemVer),因此可能会出现不兼容的更改,请在使用 Vitest 时锁定版本。
:::
-## 启动 Vitest
+## startVitest
你可以使用 Vitest 的 Node API 开始运行 Vitest 测试:
@@ -34,7 +34,7 @@ await vitest?.close()
或者,你可以将完整的 Vite 配置作为第四个参数传递进去,这将优先于任何其他用户定义的选项。
-## 创建 Vitest
+## createVitest
你可以使用 `createVitest` 函数创建自己的 Vitest 实例. 它返回与 `startVitest` 相同的 `Vitest` 实例, 但不会启动测试,也不会验证已安装的包。
@@ -62,9 +62,8 @@ Vitest 实例需要当前的测试模式。它可以是以下之一:
- 运行运行时测试时为 `test`
- 运行基准测试时为 `benchmark`
-- 运行类型测试时为 `typecheck`
-### 模式
+### 模式 {#mode}
#### test
@@ -74,53 +73,6 @@ Vitest 实例需要当前的测试模式。它可以是以下之一:
基准测试模式会调用 `bench` 函数,并在遇到 `test` 或 `it` 时抛出错误。此模式使用配置中的 `benchmark.include` 和 `benchmark.exclude` 选项查找基准测试文件。
-#### typecheck
-
-类型检查模式不会*运行*测试。它仅分析类型并提供摘要信息。此模式使用配置中的 `typecheck.include` 和 `typecheck.exclude` 选项查找要分析的文件。
-
### start
你可以使用 `start` 方法运行测试或者基准测试。你还可以传递一个字符串数组以筛选测试文件。
-
-
-### `provide`
-
-Vitest 暴露了`provide`方法,它是`vitest.getCoreWorkspaceProject().provide`的简写。使用该方法,您可以从主线程向测试传递值。所有值在存储前都会通过 `structuredClone`进行检查,但值本身不会被克隆。
-
-要在测试中接收值,需要从 `vitest` entrypont 导入 `inject` 方法:
-
-```ts
-import { inject } from 'vitest'
-const port = inject('wsPort') // 3000
-```
-
-为了提高类型安全性,我们鼓励您增强 `ProvidedContext` 的类型:
-
-```ts
-import { createVitest } from 'vitest/node'
-
-const vitest = await createVitest('test', {
- watch: false,
-})
-vitest.provide('wsPort', 3000)
-
-declare module 'vitest' {
- export interface ProvidedContext {
- wsPort: number
- }
-}
-```
-
-::: warning
-从技术上讲,`provide`是`WorkspaceProject`的一个方法,因此仅限于特定的项目。不过,所有项目都继承了核心项目的值,这使得 `vitest.provide` 成为向测试传递值的通用方法。
-:::
-
-::: tip
-在不想使用公共 API 的情况下,[全局设置文件](/config/#globalsetup) 也可以使用此方法:
-
-```js
-export default function setup({ provide }) {
- provide('wsPort', 3000)
-}
-```
-:::
diff --git a/advanced/runner.md b/advanced/runner.md
index 8340ff7f..2f04b456 100644
--- a/advanced/runner.md
+++ b/advanced/runner.md
@@ -31,7 +31,7 @@ export interface VitestRunner {
* 这是在实际运行测试函数之前被调用的。
* 此时已经有了带有 "state" 和 "startTime" 属性的 "result" 对象。
*/
- onBeforeTryTask?: (test: TaskPopulated, options: { retry: number, repeats: number }) => unknown
+ onBeforeTryTask?: (test: TaskPopulated, options: { retry: number; repeats: number }) => unknown
/**
* 这是在结果和状态都被设置之后被调用的。
*/
@@ -40,7 +40,7 @@ export interface VitestRunner {
* 这是在运行测试函数后立即被调用的。此时还没有新的状态。
* 如果测试函数抛出异常,将不会调用此方法。
*/
- onAfterTryTask?: (test: TaskPopulated, options: { retry: number, repeats: number }) => unknown
+ onAfterTryTask?: (test: TaskPopulated, options: { retry: number; repeats: number }) => unknown
/**
* 这是在运行单个测试套件之前被调用的,此时还没有测试结果。
@@ -80,7 +80,7 @@ export interface VitestRunner {
/**
* 这个方法被用于 "test" 和 "custom" 处理程序。
* 你可以在 "setupFiles" 中使用 "beforeAll" 来定义自定义上下文,而不是使用 runner。
- * 更多信息请参考:https://vitest.dev/advanced/runner.html#your-task-function
+ * 更多信息请参考:https://v1.vitest.dev/advanced/runner.html#your-task-function
*/
extendTaskContext?: (context: TaskContext) => TaskContext
/**
diff --git a/api/assert.md b/api/assert.md
index 264a2fe9..48a1131a 100644
--- a/api/assert.md
+++ b/api/assert.md
@@ -1,12 +1,12 @@
# assert
-Vitest reexports the `assert` method from [`chai`](https://www.chaijs.com/api/assert/) for verifying invariants.
+Vitest 从 [`chai`](https://www.chaijs.com/api/assert/) 重新导出了 `assert` 方法,用于验证不变量。
## assert
-- **Type:** `(expression: any, message?: string) => asserts expression`
+- **类型:** `(expression: any, message?: string) => asserts expression`
-Assert that the given `expression` is truthy, otherwise the assertion fails.
+断言给定的 `expression` 是 true,否则断言失败。
```ts
import { assert, test } from 'vitest'
@@ -18,11 +18,11 @@ test('assert', () => {
## fail
-- **Type:**
+- **类型:**
- `(message?: string) => never`
- `(actual: T, expected: T, message?: string, operator?: string) => never`
-Force an assertion failure.
+强制断言失败。
```ts
import { assert, test } from 'vitest'
@@ -35,10 +35,10 @@ test('assert.fail', () => {
## isOk
-- **Type:** `(value: T, message?: string) => void`
+- **类型:** `(value: T, message?: string) => asserts value`
- **Alias** `ok`
-Assert that the given `value` is truthy.
+断言给定的 `value` 是 true 。
```ts
import { assert, test } from 'vitest'
@@ -51,10 +51,10 @@ test('assert.isOk', () => {
## isNotOk
-- **Type:** `(value: T, message?: string) => void`
+- **类型:** `(value: T, message?: string) => void`
- **Alias** `notOk`
-Assert that the given `value` is falsy.
+断言给定的 `value` 是 false 。
```ts
import { assert, test } from 'vitest'
@@ -67,9 +67,9 @@ test('assert.isNotOk', () => {
## equal
-- **Type:** `(actual: T, expected: T, message?: string) => void`
+- **类型:** `(actual: T, expected: T, message?: string) => void`
-Asserts non-strict equality (==) of `actual` and `expected`.
+断言 `actual` 和 `expected` 非严格相等 (==)。
```ts
import { assert, test } from 'vitest'
@@ -81,9 +81,9 @@ test('assert.equal', () => {
## notEqual
-- **Type:** `(actual: T, expected: T, message?: string) => void`
+- **类型:** `(actual: T, expected: T, message?: string) => void`
-Asserts non-strict inequality (!=) of `actual` and `expected`.
+断言 `actual` 和 `expected` 非严格不等 (!=)。
```ts
import { assert, test } from 'vitest'
@@ -95,9 +95,9 @@ test('assert.equal', () => {
## strictEqual
-- **Type:** `(actual: T, expected: T, message?: string) => void`
+- **类型:** `(actual: T, expected: T, message?: string) => void`
-Asserts strict equality (===) of `actual` and `expected`.
+断言 `actual` 和 `expected` 严格相等 (===)。
```ts
import { assert, test } from 'vitest'
@@ -109,9 +109,9 @@ test('assert.strictEqual', () => {
## deepEqual
-- **Type:** `(actual: T, expected: T, message?: string) => void`
+- **类型:** `(actual: T, expected: T, message?: string) => void`
-Asserts that `actual` is deeply equal to `expected`.
+断言 `actual` 深度等于 `expected` 。
```ts
import { assert, test } from 'vitest'
@@ -123,9 +123,9 @@ test('assert.deepEqual', () => {
## notDeepEqual
-- **Type:** `(actual: T, expected: T, message?: string) => void`
+- **类型:** `(actual: T, expected: T, message?: string) => void`
-Assert that `actual` is not deeply equal to `expected`.
+断言 `actual` 不深度等于 `expected` 。
```ts
import { assert, test } from 'vitest'
@@ -137,9 +137,9 @@ test('assert.notDeepEqual', () => {
## isAbove
-- **Type:** `(valueToCheck: number, valueToBeAbove: number, message?: string) => void`
+- **类型:** `(valueToCheck: number, valueToBeAbove: number, message?: string) => void`
-Assert that `valueToCheck` is strictly greater than (>) `valueToBeAbove`.
+断言 `valueToCheck` 严格大于 (>) `valueToBeAbove` 。
```ts
import { assert, test } from 'vitest'
@@ -151,9 +151,9 @@ test('assert.isAbove', () => {
## isAtLeast
-- **Type:** `(valueToCheck: number, valueToBeAtLeast: number, message?: string) => void`
+- **类型:** `(valueToCheck: number, valueToBeAtLeast: number, message?: string) => void`
-Assert that `valueToCheck` is greater than or equal to (>=) `valueToBeAtLeast`.
+断言 `valueToCheck` 大于等于 (>=) `valueToBeAtLeast` 。
```ts
import { assert, test } from 'vitest'
@@ -166,9 +166,9 @@ test('assert.isAtLeast', () => {
## isBelow
-- **Type:** `(valueToCheck: number, valueToBeBelow: number, message?: string) => void`
+- **类型:** `(valueToCheck: number, valueToBeBelow: number, message?: string) => void`
-Asserts `valueToCheck` is strictly less than (<) `valueToBeBelow`.
+断言 `valueToCheck` 严格小于 (<) `valueToBeBelow` 。
```ts
import { assert, test } from 'vitest'
@@ -180,9 +180,9 @@ test('assert.isBelow', () => {
## isAtMost
-- **Type:** `(valueToCheck: number, valueToBeAtMost: number, message?: string) => void`
+- **类型:** `(valueToCheck: number, valueToBeAtMost: number, message?: string) => void`
-Asserts `valueToCheck` is less than or equal to (<=) `valueToBeAtMost`.
+断言 `valueToCheck` 小于等于 (<=) `valueToBeAtMost` 。
```ts
import { assert, test } from 'vitest'
@@ -195,9 +195,9 @@ test('assert.isAtMost', () => {
## isTrue
-- **Type:** `(value: T, message?: string) => void`
+- **类型:** `(value: T, message?: string) => asserts value is true`
-Asserts that `value` is true.
+断言 `value` 是 true 。
```ts
import { assert, test } from 'vitest'
@@ -211,9 +211,9 @@ test('assert.isTrue', () => {
## isNotTrue
-- **Type:** `(value: T, message?: string) => void`
+- **类型:** `(value: T, message?: string) => asserts value is Exclude`
-Asserts that `value` is not true.
+断言 `value` 不是 true 。
```ts
import { assert, test } from 'vitest'
@@ -227,9 +227,9 @@ test('assert.isNotTrue', () => {
## isFalse
-- **Type:** `(value: T, message?: string) => void`
+- **类型:** `(value: T, message?: string) => asserts value is false`
-Asserts that `value` is false.
+断言 `value` 是 false 。
```ts
import { assert, test } from 'vitest'
@@ -243,9 +243,9 @@ test('assert.isFalse', () => {
## isNotFalse
-- **Type:** `(value: T, message?: string) => void`
+- **类型:** `(value: T, message?: string) => asserts value is Exclude`
-Asserts that `value` is not false.
+断言 `value` 不是 false 。
```ts
import { assert, test } from 'vitest'
@@ -259,9 +259,9 @@ test('assert.isNotFalse', () => {
## isNull
-- **Type:** `(value: T, message?: string) => void`
+- **类型:** `(value: T, message?: string) => asserts value is null`
-Asserts that `value` is null.
+断言 `value` 是 null 。
```ts
import { assert, test } from 'vitest'
@@ -275,14 +275,14 @@ test('assert.isNull', () => {
## isNotNull
-- **Type:** `(value: T, message?: string) => void`
+- **类型:** `(value: T, message?: string) => asserts value is Exclude`
-Asserts that `value` is not null.
+断言 `value` 不是 null 。
```ts
import { assert, test } from 'vitest'
-const error = { message: 'error was occured' }
+const error = { message: 'error was occurred' }
test('assert.isNotNull', () => {
assert.isNotNull(error, 'error is not null but object')
@@ -291,14 +291,14 @@ test('assert.isNotNull', () => {
## isNaN
-- **Type:** `(value: T, message?: string) => void`
+- **类型:** `(value: T, message?: string) => void`
-Asserts that `value` is NaN.
+断言 `value` 是 NaN 。
```ts
import { assert, test } from 'vitest'
-const calculation = 1 * 'viitest'
+const calculation = 1 * 'vitest'
test('assert.isNaN', () => {
assert.isNaN(calculation, '1 * "vitest" is NaN')
@@ -307,9 +307,9 @@ test('assert.isNaN', () => {
## isNotNaN
-- **Type:** `(value: T, message?: string) => void`
+- **类型:** `(value: T, message?: string) => void`
-Asserts that `value` is not NaN.
+断言 `value` 不是 NaN 。
```ts
import { assert, test } from 'vitest'
@@ -323,9 +323,9 @@ test('assert.isNotNaN', () => {
## exists
-- **Type:** `(value: T, message?: string) => void`
+- **类型:** `(value: T, message?: string) => void`
-Asserts that `value` is neither null nor undefined.
+断言 `value` 既不是 null 也不是 undefined 。
```ts
import { assert, test } from 'vitest'
@@ -339,9 +339,9 @@ test('assert.exists', () => {
## notExists
-- **Type:** `(value: T, message?: string) => void`
+- **类型:** `(value: T, message?: string) => void`
-Asserts that `value` is either null nor undefined.
+断言 `value` 是 null 或 undefined 。
```ts
import { assert, test } from 'vitest'
@@ -357,9 +357,9 @@ test('assert.notExists', () => {
## isUndefined
-- **Type:** `(value: T, message?: string) => void`
+- **类型:** `(value: T, message?: string) => void`
-Asserts that `value` is undefined.
+断言 `value` 是 undefined 。
```ts
import { assert, test } from 'vitest'
@@ -373,9 +373,9 @@ test('assert.isUndefined', () => {
## isDefined
-- **Type:** `(value: T, message?: string) => void`
+- **类型:** `(value: T, message?: string) => void`
-Asserts that `value` is not undefined.
+断言 `value` 不是 undefined 。
```ts
import { assert, test } from 'vitest'
@@ -389,9 +389,9 @@ test('assert.isDefined', () => {
## isFunction
-- **Type:** `(value: T, message?: string) => void`
-- **Alias:** `isCallable`
- Asserts that `value` is a function.
+- **类型:** `(value: T, message?: string) => void`
+- **别名:** `isCallable`
+ 断言 `value` 是一个函数。
```ts
import { assert, test } from 'vitest'
@@ -407,10 +407,10 @@ test('assert.isFunction', () => {
## isNotFunction
-- **Type:** `(value: T, message?: string) => void`
-- **Alias:** `isNotCallable`
+- **类型:** `(value: T, message?: string) => void`
+- **别名:** `isNotCallable`
-Asserts that `value` is not a function.
+断言 `value` 不是一个函数。
```ts
import { assert, test } from 'vitest'
@@ -424,9 +424,9 @@ test('assert.isNotFunction', () => {
## isObject
-- **Type:** `(value: T, message?: string) => void`
+- **类型:** `(value: T, message?: string) => void`
-Asserts that `value` is an object of type Object (as revealed by Object.prototype.toString). The assertion does not match subclassed objects.
+断言 `value` 是一个类型为 Object 的对象 (由 Object.prototype.toString 确定)。 此断言不匹配子类对象。
```ts
import { assert, test } from 'vitest'
@@ -440,9 +440,9 @@ test('assert.isObject', () => {
## isNotObject
-- **Type:** `(value: T, message?: string) => void`
+- **类型:** `(value: T, message?: string) => void`
-Asserts that `value` is not an object of type Object (as revealed by Object.prototype.toString). The assertion does not match subclassed objects.
+断言 `value` 不是一个类型为 Object 的对象 (如 Object.prototype.toString 确定)。 该断言不匹配子类对象。
```ts
import { assert, test } from 'vitest'
@@ -456,9 +456,9 @@ test('assert.isNotObject', () => {
## isArray
-- **Type:** `(value: T, message?: string) => void`
+- **类型:** `(value: T, message?: string) => void`
-Asserts that `value` is an array.
+断言 `value` 是一个数组。
```ts
import { assert, test } from 'vitest'
@@ -472,9 +472,9 @@ test('assert.isArray', () => {
## isNotArray
-- **Type:** `(value: T, message?: string) => void`
+- **类型:** `(value: T, message?: string) => void`
-Asserts that `value` is not an array.
+断言 `value` 不是一个数组。
```ts
import { assert, test } from 'vitest'
@@ -488,9 +488,9 @@ test('assert.isNotArray', () => {
## isString
-- **Type:** `(value: T, message?: string) => void`
+- **类型:** `(value: T, message?: string) => void`
-Asserts that `value` is a string.
+断言 `value` 是一个字符串。
```ts
import { assert, test } from 'vitest'
@@ -504,9 +504,9 @@ test('assert.isString', () => {
## isNotString
-- **Type:** `(value: T, message?: string) => void`
+- **类型:** `(value: T, message?: string) => void`
-Asserts that `value` is not a string.
+断言 `value` 不是一个字符串。
```ts
import { assert, test } from 'vitest'
@@ -520,9 +520,9 @@ test('assert.isNotString', () => {
## isNumber
-- **Type:** `(value: T, message?: string) => void`
+- **类型:** `(value: T, message?: string) => void`
-Asserts that `value` is a number.
+断言 `value` 是一个数字。
```ts
import { assert, test } from 'vitest'
@@ -536,9 +536,9 @@ test('assert.isNumber', () => {
## isNotNumber
-- **Type:** `(value: T, message?: string) => void`
+- **类型:** `(value: T, message?: string) => void`
-Asserts that `value` is not a number.
+断言 `value` 不是一个数字。
```ts
import { assert, test } from 'vitest'
@@ -552,9 +552,9 @@ test('assert.isNotNumber', () => {
## isFinite
-- **Type:** `(value: T, message?: string) => void`
+- **类型:** `(value: T, message?: string) => void`
-Asserts that `value` is a finite number (not NaN, Infinity).
+断言 `value` 是一个有限数字。(不是 NaN, Infinity)。
```ts
import { assert, test } from 'vitest'
@@ -568,9 +568,9 @@ test('assert.isFinite', () => {
## isBoolean
-- **Type:** `(value: T, message?: string) => void`
+- **类型:** `(value: T, message?: string) => void`
-Asserts that `value` is a boolean.
+断言 `value` 是一个布尔值。
```ts
import { assert, test } from 'vitest'
@@ -584,9 +584,9 @@ test('assert.isBoolean', () => {
## isNotBoolean
-- **Type:** `(value: T, message?: string) => void`
+- **类型:** `(value: T, message?: string) => void`
-Asserts that `value` is not a boolean.
+断言 `value` 不是一个布尔值。
```ts
import { assert, test } from 'vitest'
@@ -600,9 +600,9 @@ test('assert.isBoolean', () => {
## typeOf
-- **Type:** `(value: T, name: string, message?: string) => void`
+- **类型:** `(value: T, name: string, message?: string) => void`
-Asserts that `value`’s type is `name`, as determined by Object.prototype.toString.
+断言 `value` 的类型是 `name`, 由 Object.prototype.toString 确定。
```ts
import { assert, test } from 'vitest'
@@ -619,9 +619,9 @@ test('assert.typeOf', () => {
## notTypeOf
-- **Type:** `(value: T, name: string, message?: string) => void`
+- **类型:** `(value: T, name: string, message?: string) => void`
-Asserts that `value`’s type is not `name`, as determined by Object.prototype.toString.
+断言 `value` 的类型不是 `name`,由 Object.prototype.toString 确定。
```ts
import { assert, test } from 'vitest'
@@ -633,16 +633,14 @@ test('assert.notTypeOf', () => {
## instanceOf
-- **Type:** `(value: T, constructor: Function, message?: string) => void`
+- **类型:** `(value: T, constructor: Function, message?: string) => asserts value is T`
-Asserts that `value` is an instance of `constructor`.
+断言 `value` 是 `constructor` 的实例。
```ts
import { assert, test } from 'vitest'
-function Person(name) {
- this.name = name
-}
+function Person(name) { this.name = name }
const foo = new Person('foo')
class Tea {
@@ -660,16 +658,14 @@ test('assert.instanceOf', () => {
## notInstanceOf
-- **Type:** `(value: T, constructor: Function, message?: string) => void`
+- **类型:** `(value: T, constructor: Function, message?: string) => asserts value is Exclude`
-Asserts that `value` is not an instance of `constructor`.
+断言 `value` 不是 `constructor` 的实例。
```ts
import { assert, test } from 'vitest'
-function Person(name) {
- this.name = name
-}
+function Person(name) { this.name = name }
const foo = new Person('foo')
class Tea {
@@ -686,13 +682,13 @@ test('assert.instanceOf', () => {
## include
-- **Type:**
+- **类型:**
- `(haystack: string, needle: string, message?: string) => void`
- `(haystack: readonly T[] | ReadonlySet | ReadonlyMap, needle: T, message?: string) => void`
- `(haystack: WeakSet, needle: T, message?: string) => void`
- `(haystack: T, needle: Partial, message?: string) => void`
-Asserts that `haystack` includes `needle`. Can be used to assert the inclusion of a value in an array, a substring in a string, or a subset of properties in an object.
+断言 `haystack` 包含 `needle` 。可以用来断言数组中是否包含一个值、字符串中是否包含一个子字符串、或者对象中是否包含一组属性。
```ts
import { assert, test } from 'vitest'
@@ -700,23 +696,19 @@ import { assert, test } from 'vitest'
test('assert.include', () => {
assert.include([1, 2, 3], 2, 'array contains value')
assert.include('foobar', 'foo', 'string contains substring')
- assert.include(
- { foo: 'bar', hello: 'universe' },
- { foo: 'bar' },
- 'object contains property'
- )
+ assert.include({ foo: 'bar', hello: 'universe' }, { foo: 'bar' }, 'object contains property')
})
```
## notInclude
-- **Type:**
+- **类型:**
- `(haystack: string, needle: string, message?: string) => void`
- `(haystack: readonly T[] | ReadonlySet | ReadonlyMap, needle: T, message?: string) => void`
- `(haystack: WeakSet, needle: T, message?: string) => void`
- `(haystack: T, needle: Partial, message?: string) => void`
-Asserts that `haystack` does not include `needle`. It can be used to assert the absence of a value in an array, a substring in a string, or a subset of properties in an object.
+断言 `haystack` 不包含 `needle` 。可以用来断言数组中是否不包含一个值、字符串中是否不包含一个子字符串、或者对象中是否不包含一组属性。
```ts
import { assert, test } from 'vitest'
@@ -724,22 +716,18 @@ import { assert, test } from 'vitest'
test('assert.notInclude', () => {
assert.notInclude([1, 2, 3], 4, 'array doesn\'t contain 4')
assert.notInclude('foobar', 'baz', 'foobar doesn\'t contain baz')
- assert.notInclude(
- { foo: 'bar', hello: 'universe' },
- { foo: 'baz' },
- 'object doesn\'t contain property'
- )
+ assert.notInclude({ foo: 'bar', hello: 'universe' }, { foo: 'baz' }, 'object doesn\'t contain property')
})
```
## deepInclude
-- **Type:**
+- **类型:**
- `(haystack: string, needle: string, message?: string) => void`
- `(haystack: readonly T[] | ReadonlySet | ReadonlyMap, needle: T, message?: string) => void`
- `(haystack: T, needle: T extends WeakSet ? never : Partial, message?: string) => void`
-Asserts that `haystack` includes `needle`. Can be used to assert the inclusion of a value in an array or a subset of properties in an object. Deep equality is used.
+断言 `haystack` 包含 `needle` 。可以用来断言数组中是否包含一个值或对象中是否包含一组属性。使用深度相等。
```ts
import { assert, test } from 'vitest'
@@ -755,12 +743,12 @@ test('assert.deepInclude', () => {
## notDeepInclude
-- **Type:**
+- **类型:**
- `(haystack: string, needle: string, message?: string) => void`
- `(haystack: readonly T[] | ReadonlySet | ReadonlyMap, needle: T, message?: string) => void`
- `(haystack: T, needle: T extends WeakSet ? never : Partial, message?: string) => void`
-Asserts that `haystack` does not include `needle`. It can be used to assert the absence of a value in an array or a subset of properties in an object. Deep equality is used.
+断言 `haystack` 不包含 `needle` 。可以用来断言数组中是否不包含一个值或对象中是否不包含一组属性。使用深度相等。
```ts
import { assert, test } from 'vitest'
@@ -776,9 +764,9 @@ test('assert.notDeepInclude', () => {
## nestedInclude
-- **Type:** `(haystack: any, needle: any, message?: string) => void`
+- **类型:** `(haystack: any, needle: any, message?: string) => void`
-Asserts that `haystack` includes `needle`. Can be used to assert the inclusion of a subset of properties in an object. Enables the use of dot- and bracket-notation for referencing nested properties. ‘[]’ and ‘.’ in property names can be escaped using double backslashes.
+断言 `haystack` 包含 `needle` 。 可以用来断言对象中是否包含一组属性。允许使用点和括号表示法来引用嵌套属性。属性名中的 ‘[]’ 和 ‘.’ 可以使用双反斜杠转义。
```ts
import { assert, test } from 'vitest'
@@ -791,9 +779,9 @@ test('assert.nestedInclude', () => {
## notNestedInclude
-- **Type:** `(haystack: any, needle: any, message?: string) => void`
+- **类型:** `(haystack: any, needle: any, message?: string) => void`
-Asserts that `haystack` does not include `needle`. Can be used to assert the inclusion of a subset of properties in an object. Enables the use of dot- and bracket-notation for referencing nested properties. ‘[]’ and ‘.’ in property names can be escaped using double backslashes.
+断言 `haystack` 不包含 `needle` 。可以用来断言对象中是否不包含一组属性。允许使用点和括号表示法来引用嵌套属性。属性名中的 ‘[]’ 和 ‘.’ 可以使用双反斜杠转义。
```ts
import { assert, test } from 'vitest'
@@ -806,45 +794,39 @@ test('assert.nestedInclude', () => {
## deepNestedInclude
-- **Type:** `(haystack: any, needle: any, message?: string) => void`
+- **类型:** `(haystack: any, needle: any, message?: string) => void`
-Asserts that `haystack` includes `needle`. Can be used to assert the inclusion of a subset of properties in an object while checking for deep equality. Enables the use of dot- and bracket-notation for referencing nested properties. ‘[]’ and ‘.’ in property names can be escaped using double backslashes.
+断言 `haystack` 包含 `needle` 。可以用来断言对象中是否包含一组属性,同时检查深度相等性。允许使用点和括号表示法来引用嵌套属性。属性名中的 ‘[]’ 和 ‘.’ 可以使用双反斜杠转义。
```ts
import { assert, test } from 'vitest'
test('assert.deepNestedInclude', () => {
assert.deepNestedInclude({ a: { b: [{ x: 1 }] } }, { 'a.b[0]': { x: 1 } })
- assert.deepNestedInclude(
- { '.a': { '[b]': { x: 1 } } },
- { '\\.a.\\[b\\]': { x: 1 } }
- )
+ assert.deepNestedInclude({ '.a': { '[b]': { x: 1 } } }, { '\\.a.\\[b\\]': { x: 1 } })
})
```
## notDeepNestedInclude
-- **Type:** `(haystack: any, needle: any, message?: string) => void`
+- **类型:** `(haystack: any, needle: any, message?: string) => void`
-Asserts that `haystack` not includes `needle`. Can be used to assert the absence of a subset of properties in an object while checking for deep equality. Enables the use of dot- and bracket-notation for referencing nested properties. ‘[]’ and ‘.’ in property names can be escaped using double backslashes.
+断言 `haystack` 不包含 `needle` 。可以用来断言对象中是否不包含一组属性,同时检查深度相等性。允许使用点和括号表示法来引用嵌套属性。属性名中的 ‘[]’ 和 ‘.’ 可以使用双反斜杠转义。
```ts
import { assert, test } from 'vitest'
test('assert.notDeepNestedInclude', () => {
assert.notDeepNestedInclude({ a: { b: [{ x: 1 }] } }, { 'a.b[0]': { y: 1 } })
- assert.notDeepNestedInclude(
- { '.a': { '[b]': { x: 1 } } },
- { '\\.a.\\[b\\]': { y: 2 } }
- )
+ assert.notDeepNestedInclude({ '.a': { '[b]': { x: 1 } } }, { '\\.a.\\[b\\]': { y: 2 } })
})
```
## ownInclude
-- **Type:** `(haystack: any, needle: any, message?: string) => void`
+- **类型:** `(haystack: any, needle: any, message?: string) => void`
-Asserts that `haystack` includes `needle`. Can be used to assert the inclusion of a subset of properties in an object while ignoring inherited properties.
+断言 `haystack` 包含 `needle` 。可以用来断言对象中是否包含一组属性,同时忽略继承的属性。
```ts
import { assert, test } from 'vitest'
@@ -856,9 +838,9 @@ test('assert.ownInclude', () => {
## notOwnInclude
-- **Type:** `(haystack: any, needle: any, message?: string) => void`
+- **类型:** `(haystack: any, needle: any, message?: string) => void`
-Asserts that `haystack` includes `needle`. Can be used to assert the absence of a subset of properties in an object while ignoring inherited properties.
+断言 `haystack` 包含 `needle` 。可以用来断言对象中是否不包含一组属性,同时忽略继承的属性
```ts
import { assert, test } from 'vitest'
@@ -877,9 +859,9 @@ test('assert.notOwnInclude', () => {
## deepOwnInclude
-- **Type:** `(haystack: any, needle: any, message?: string) => void`
+- **类型:** `(haystack: any, needle: any, message?: string) => void`
-Asserts that `haystack` includes `needle`. Can be used to assert the inclusion of a subset of properties in an object while ignoring inherited properties and checking for deep equality.
+断言 `haystack` 包含 `needle` 。可以用来断言对象中是否包含一组属性,同时忽略继承的属性并检查深度相等性。
```ts
import { assert, test } from 'vitest'
@@ -891,9 +873,9 @@ test('assert.deepOwnInclude', () => {
## notDeepOwnInclude
-- **Type:** `(haystack: any, needle: any, message?: string) => void`
+- **类型:** `(haystack: any, needle: any, message?: string) => void`
-Asserts that `haystack` not includes `needle`. Can be used to assert the absence of a subset of properties in an object while ignoring inherited properties and checking for deep equality.
+断言 `haystack` 不包含 `needle` 。可以用来断言对象中是否不包含一组属性,同时忽略继承的属性并检查深度相等性。
```ts
import { assert, test } from 'vitest'
@@ -905,9 +887,9 @@ test('assert.notDeepOwnInclude', () => {
## match
-- **Type:** `(value: string, regexp: RegExp, message?: string) => void`
+- **类型:** `(value: string, regexp: RegExp, message?: string) => void`
-Asserts that `value` matches the regular expression `regexp`.
+断言 `value` 匹配正则表达式 `regexp` 。
```ts
import { assert, test } from 'vitest'
@@ -919,9 +901,9 @@ test('assert.match', () => {
## notMatch
-- **Type:** `(value: string, regexp: RegExp, message?: string) => void`
+- **类型:** `(value: string, regexp: RegExp, message?: string) => void`
-Asserts that `value` does not matches the regular expression `regexp`.
+断言 `value` 不匹配正则表达式 `regexp` 。
```ts
import { assert, test } from 'vitest'
@@ -933,9 +915,9 @@ test('assert.notMatch', () => {
## property
-- **Type:** `(object: T, property: string, message?: string) => void`
+- **类型:** `(object: T, property: string, message?: string) => void`
-Asserts that `object` has a direct or inherited property named by `property`
+断言 `object` 具有由 `property` 指定的直接或继承属性。
```ts
import { assert, test } from 'vitest'
@@ -948,9 +930,9 @@ test('assert.property', () => {
## notProperty
-- **Type:** `(object: T, property: string, message?: string) => void`
+- **类型:** `(object: T, property: string, message?: string) => void`
-Asserts that `object` does not have a direct or inherited property named by `property`
+断言 `object` 没有由 `property` 指定的直接或继承属性。
```ts
import { assert, test } from 'vitest'
@@ -962,9 +944,9 @@ test('assert.notProperty', () => {
## propertyVal
-- **Type:** `(object: T, property: string, value: V, message?: string) => void`
+- **类型:** `(object: T, property: string, value: V, message?: string) => void`
-Asserts that `object` has a direct or inherited property named by `property` with a value given by `value`. Uses a strict equality check (===).
+断言 `object` 具有由 `property` 指定的直接或继承属性,其值为 `value` 。使用严格相等检查(===)。
```ts
import { assert, test } from 'vitest'
@@ -976,9 +958,9 @@ test('assert.notPropertyVal', () => {
## notPropertyVal
-- **Type:** `(object: T, property: string, value: V, message?: string) => void`
+- **类型:** `(object: T, property: string, value: V, message?: string) => void`
-Asserts that `object` does not have a direct or inherited property named by `property` with a value given by `value`. Uses a strict equality check (===).
+断言 `object` 没有由 `property` 指定的直接或继承属性,其值为 `value` 。使用严格相等检查(===)。
```ts
import { assert, test } from 'vitest'
@@ -991,9 +973,9 @@ test('assert.notPropertyVal', () => {
## deepPropertyVal
-- **Type:** `(object: T, property: string, value: V, message?: string) => void`
+- **类型:** `(object: T, property: string, value: V, message?: string) => void`
-Asserts that `object` has a direct or inherited property named by `property` with a value given by `value`. Uses a deep equality check.
+断言 `object` 具有由 `property` 指定的直接或继承属性,其值为 `value` 。使用深度相等检查。
```ts
import { assert, test } from 'vitest'
@@ -1007,31 +989,25 @@ test('assert.deepPropertyVal', () => {
## notDeepPropertyVal
-- **Type:** `(object: T, property: string, value: V, message?: string) => void`
+- **类型:** `(object: T, property: string, value: V, message?: string) => void`
-Asserts that `object` does not have a direct or inherited property named by `property` with a value given by `value`. Uses a deep equality check.
+断言 `object` 没有由 `property` 指定的直接或继承属性,其值为 `value` 。使用深度相等检查。
```ts
import { assert, test } from 'vitest'
test('assert.deepPropertyVal', () => {
- assert.notDeepPropertyVal({ tea: { green: 'matcha' } }, 'tea', {
- black: 'matcha',
- })
- assert.notDeepPropertyVal({ tea: { green: 'matcha' } }, 'tea', {
- green: 'oolong',
- })
- assert.notDeepPropertyVal({ tea: { green: 'matcha' } }, 'coffee', {
- green: 'matcha',
- })
+ assert.notDeepPropertyVal({ tea: { green: 'matcha' } }, 'tea', { black: 'matcha', })
+ assert.notDeepPropertyVal({ tea: { green: 'matcha' } }, 'tea', { green: 'oolong', })
+ assert.notDeepPropertyVal({ tea: { green: 'matcha' } }, 'coffee', { green: 'matcha', })
})
```
## nestedProperty
-- **Type:** `(object: T, property: string, message?: string) => void`
+- **类型:** `(object: T, property: string, message?: string) => void`
-Asserts that `object` has a direct or inherited property named by `property`, which can be a string using dot- and bracket-notation for nested reference.
+断言 `object` 具有由 `property` 指定的直接或继承属性,它可以是一个字符串,使用点和括号表示法来引用嵌套的引用。
```ts
import { assert, test } from 'vitest'
@@ -1043,9 +1019,9 @@ test('assert.deepPropertyVal', () => {
## notNestedProperty
-- **Type:** `(object: T, property: string, message?: string) => void`
+- **类型:** `(object: T, property: string, message?: string) => void`
-Asserts that `object` does not have a direct or inherited property named by `property`, which can be a string using dot- and bracket-notation for nested reference.
+断言 `object` 没有由 `property` 指定的属性,它可以是一个字符串,使用点和括号表示法来引用嵌套的引用。该属性不能存在于对象上,也不能存在于其原型链中的任何地方。
```ts
import { assert, test } from 'vitest'
@@ -1057,9 +1033,9 @@ test('assert.deepPropertyVal', () => {
## nestedPropertyVal
-- **Type:** `(object: T, property: string, value: any, message?: string) => void`
+- **类型:** `(object: T, property: string, value: any, message?: string) => void`
-Asserts that `object` has a property named by `property` with value given by `value`. `property` can use dot- and bracket-notation for nested reference. Uses a strict equality check (===).
+断言 `object` 具有由 `property` 指定的属性,其值为 `value` 给出。 `property` 可以使用点和方括号表示法进行嵌套引用。使用严格相等检查 (===)。
```ts
import { assert, test } from 'vitest'
@@ -1071,83 +1047,55 @@ test('assert.nestedPropertyVal', () => {
## notNestedPropertyVal
-- **Type:** `(object: T, property: string, value: any, message?: string) => void`
+- **类型:** `(object: T, property: string, value: any, message?: string) => void`
-Asserts that `object` does not have a property named by `property` with value given by `value`. `property` can use dot- and bracket-notation for nested reference. Uses a strict equality check (===).
+断言 `object` 没有由 `property` 指定的属性,其值为 `value` 给出。 `property` 可以使用点和方括号表示法进行嵌套引用。使用严格相等检查 (===)。
```ts
import { assert, test } from 'vitest'
test('assert.notNestedPropertyVal', () => {
- assert.notNestedPropertyVal(
- { tea: { green: 'matcha' } },
- 'tea.green',
- 'konacha'
- )
- assert.notNestedPropertyVal(
- { tea: { green: 'matcha' } },
- 'coffee.green',
- 'matcha'
- )
+ assert.notNestedPropertyVal({ tea: { green: 'matcha' } }, 'tea.green', 'konacha')
+ assert.notNestedPropertyVal({ tea: { green: 'matcha' } }, 'coffee.green', 'matcha')
})
```
## deepNestedPropertyVal
-- **Type:** `(object: T, property: string, value: any, message?: string) => void`
+- **类型:** `(object: T, property: string, value: any, message?: string) => void`
-Asserts that `object` has a property named by `property` with a value given by `value`. `property` can use dot- and bracket-notation for nested reference. Uses a deep equality check (===).
+断言 `object` 具有由 `property` 指定的属性,其值为 `value` 给出。 `property` 可以使用点和方括号表示法进行嵌套引用。使用深度相等检查。
```ts
import { assert, test } from 'vitest'
test('assert.notNestedPropertyVal', () => {
- assert.notNestedPropertyVal(
- { tea: { green: 'matcha' } },
- 'tea.green',
- 'konacha'
- )
- assert.notNestedPropertyVal(
- { tea: { green: 'matcha' } },
- 'coffee.green',
- 'matcha'
- )
+ assert.notNestedPropertyVal({ tea: { green: 'matcha' } }, 'tea.green', 'konacha')
+ assert.notNestedPropertyVal({ tea: { green: 'matcha' } }, 'coffee.green', 'matcha')
})
```
## notDeepNestedPropertyVal
-- **Type:** `(object: T, property: string, value: any, message?: string) => void`
+- **类型:** `(object: T, property: string, value: any, message?: string) => void`
-Asserts that `object` does not have a property named by `property` with value given by `value`. `property` can use dot- and bracket-notation for nested reference. Uses a deep equality check.
+断言 `object` 没有由 `property` 指定的属性,其值为 `value` 给出。 `property` 可以使用点和方括号表示法进行嵌套引用。使用深度相等检查。
```ts
import { assert, test } from 'vitest'
test('assert.notDeepNestedPropertyVal', () => {
- assert.notDeepNestedPropertyVal(
- { tea: { green: { matcha: 'yum' } } },
- 'tea.green',
- { oolong: 'yum' }
- )
- assert.notDeepNestedPropertyVal(
- { tea: { green: { matcha: 'yum' } } },
- 'tea.green',
- { matcha: 'yuck' }
- )
- assert.notDeepNestedPropertyVal(
- { tea: { green: { matcha: 'yum' } } },
- 'tea.black',
- { matcha: 'yum' }
- )
+ assert.notDeepNestedPropertyVal({ tea: { green: { matcha: 'yum' } } }, 'tea.green', { oolong: 'yum' })
+ assert.notDeepNestedPropertyVal({ tea: { green: { matcha: 'yum' } } }, 'tea.green', { matcha: 'yuck' })
+ assert.notDeepNestedPropertyVal({ tea: { green: { matcha: 'yum' } } }, 'tea.black', { matcha: 'yum' })
})
```
## lengthOf
-- **Type:** `(object: T, length: number, message?: string) => void`
+- **类型:** `(object: T, length: number, message?: string) => void`
-Asserts that `object` has a `length` or `size` with the expected value.
+断言 `object` 具有预期的 `length` 或 `size` 值。
```ts
import { assert, test } from 'vitest'
@@ -1156,80 +1104,49 @@ test('assert.lengthOf', () => {
assert.lengthOf([1, 2, 3], 3, 'array has length of 3')
assert.lengthOf('foobar', 6, 'string has length of 6')
assert.lengthOf(new Set([1, 2, 3]), 3, 'set has size of 3')
- assert.lengthOf(
- new Map([
- ['a', 1],
- ['b', 2],
- ['c', 3],
- ]),
- 3,
- 'map has size of 3'
- )
+ assert.lengthOf(new Map([['a', 1], ['b', 2], ['c', 3]]), 3, 'map has size of 3')
})
```
## hasAnyKeys
-- **Type:** `(object: T, keys: Array