Skip to content

Commit d890c3a

Browse files
committed
docs: translate browser
1 parent b381748 commit d890c3a

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

guide/browser/index.md

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ outline: deep
88
此页面提供有关 Vitest API 中实验性浏览器模式功能的信息,该功能允许你在浏览器中本地运行测试,提供对窗口和文档等浏览器全局变量的访问。此功能目前正在开发中,API 未来可能会更改。
99

1010
::: tip
11-
If you are looking for documentation for `expect`, `vi` or any general API like workspaces or type testing, refer to the ["Getting Started" guide](/guide/).
11+
如果你正在寻找关于 `expect``vi` 或任何通用 API(如工作区或类型测试)的文档,请参阅 ["入门指南"](./guide/)
1212
:::
1313

1414
<img alt="Vitest UI" img-light src="/ui-browser-1-light.png">
@@ -206,8 +206,7 @@ import { defineWorkspace } from 'vitest/config'
206206
export default defineWorkspace([
207207
{
208208
test: {
209-
// an example of file based convention,
210-
// you don't have to follow it
209+
// 文件约定的示例,你不必遵循它。
211210
include: [
212211
'tests/unit/**/*.{test,spec}.ts',
213212
'tests/**/*.unit.{test,spec}.ts',
@@ -218,8 +217,7 @@ export default defineWorkspace([
218217
},
219218
{
220219
test: {
221-
// an example of file based convention,
222-
// you don't have to follow it
220+
// 文件约定的示例,你不必遵循它。
223221
include: [
224222
'tests/browser/**/*.{test,spec}.ts',
225223
'tests/**/*.browser.{test,spec}.ts',
@@ -409,14 +407,13 @@ import { render } from './my-render-function.js'
409407
test('properly handles form inputs', async () => {
410408
render() // mount DOM elements
411409

412-
// Asserts initial state.
410+
// 断言初始状态。
413411
await expect.element(page.getByText('Hi, my name is Alice')).toBeInTheDocument()
414412

415-
// Get the input DOM node by querying the associated label.
413+
// 通过查询关联的标签获取输入的 DOM 节点。
416414
const usernameInput = page.getByLabelText(/username/i)
417415

418-
// Type the name into the input. This already validates that the input
419-
// is filled correctly, no need to check the value manually.
416+
// 将名称输入到输入框中。这已经验证了输入框中的值是正确的,无需手动检查其值。
420417
await usernameInput.fill('Bob')
421418

422419
await expect.element(page.getByText('Hi, my name is Bob')).toBeInTheDocument()
@@ -456,14 +453,13 @@ import Component from './Component.vue'
456453
test('properly handles v-model', async () => {
457454
const screen = render(Component)
458455

459-
// Asserts initial state.
456+
// 断言初始状态。
460457
await expect.element(screen.getByText('Hi, my name is Alice')).toBeInTheDocument()
461458

462-
// Get the input DOM node by querying the associated label.
459+
// 通过查询关联的标签获取输入的 DOM 节点。
463460
const usernameInput = screen.getByLabelText(/username/i)
464461

465-
// Type the name into the input. This already validates that the input
466-
// is filled correctly, no need to check the value manually.
462+
// 将名称输入到输入框中。这已经验证了输入框中的值是正确的,无需手动检查其值。
467463
await usernameInput.fill('Bob')
468464

469465
await expect.element(screen.getByText('Hi, my name is Bob')).toBeInTheDocument()
@@ -490,14 +486,14 @@ import { render } from 'vitest-browser-react'
490486
import Fetch from './fetch'
491487

492488
test('loads and displays greeting', async () => {
493-
// Render a React element into the DOM
489+
// 将一个 React 元素渲染到 DOM 中。
494490
const screen = render(<Fetch url="/greeting" />)
495491

496492
await screen.getByText('Load Greeting').click()
497-
// wait before throwing an error if it cannot find an element
493+
// 如果找不到元素,则等待一段时间后再抛出错误。
498494
const heading = screen.getByRole('heading')
499495

500-
// assert that the alert message is correct
496+
// 断言警告消息是正确的。
501497
await expect.element(heading).toHaveTextContent('hello there')
502498
await expect.element(screen.getByRole('button')).toBeDisabled()
503499
})
@@ -538,12 +534,11 @@ test('shows the children when the checkbox is checked', async () => {
538534

539535
const screen = page.elementLocator(baseElement)
540536

541-
// .query() will return the element or null if it cannot be found.
542-
// .element() will return the element or throw an error if it cannot be found.
537+
// .query() 将返回找到的元素或在未找到时返回 null
538+
// .element() 会返回该元素,如果找不到该元素则会抛出错误。
543539
expect(screen.getByText(testMessage).query()).not.toBeInTheDocument()
544540

545-
// The queries can accept a regex to make your selectors more
546-
// resilient to content tweaks and changes.
541+
// 查询可以接受正则表达式,使选择器更能适应内容的调整和变化。
547542
await screen.getByLabelText(/show/i).click()
548543

549544
await expect.element(screen.getByText(testMessage)).toBeInTheDocument()

0 commit comments

Comments
 (0)