@@ -106,7 +106,7 @@ export default defineConfig({
106106 browser: {
107107 provider: playwright (),
108108 enabled: true ,
109- // at least one instance is required
109+ // 至少需要一个实例
110110 instances: [
111111 { browser: ' chromium' },
112112 ],
@@ -214,7 +214,7 @@ export default defineConfig({
214214import { qwikVite } from ' @builder.io/qwik/optimizer'
215215import { playwright } from ' @vitest/browser-playwright'
216216
217- // optional, run the tests in SSR mode
217+ // 可选项,在 SSR 模式下运行测试
218218import { testSSR } from ' vitest-browser-qwik/ssr-plugin'
219219
220220import { defineConfig } from ' vitest/config'
@@ -245,8 +245,8 @@ export default defineConfig({
245245 projects: [
246246 {
247247 test: {
248- // an example of file based convention,
249- // you don't have to follow it
248+ // 一个基于文件的惯例的例子,
249+ // 你不用必需遵守它
250250 include: [
251251 ' tests/unit/**/*.{test,spec}.ts' ,
252252 ' tests/**/*.unit.{test,spec}.ts' ,
@@ -257,8 +257,8 @@ export default defineConfig({
257257 },
258258 {
259259 test: {
260- // an example of file based convention,
261- // you don't have to follow it
260+ // 一个基于文件的惯例的例子,
261+ // 你不用必需遵守它
262262 include: [
263263 ' tests/browser/**/*.{test,spec}.ts' ,
264264 ' tests/**/*.browser.{test,spec}.ts' ,
@@ -278,7 +278,7 @@ export default defineConfig({
278278})
279279```
280280
281- ## Browser Option Types
281+ ## 浏览器选项的类型
282282
283283Vitest 中的浏览器选项取决于provider。如果在配置文件中传递 ` --browser ` 且未指定其名称,则 Vitest 将失败。可用选项:
284284- ` webdriverio ` 支持这些浏览器:
@@ -291,7 +291,7 @@ Vitest 中的浏览器选项取决于provider。如果在配置文件中传递 `
291291 - ` webkit `
292292 - ` chromium `
293293
294- ## Browser Compatibility
294+ ## 浏览器的兼容性
295295
296296Vitest 使用 [ Vite dev server] ( https://cn.vitejs.dev/guide/#browser-support ) 来运行我们的测试,因此我们只支持 [ ` esbuild.target ` ] ( https://cn.vitejs.dev/config/shared-options#esbuild ) 选项(默认为 ` esnext ` )中指定的功能。
297297
@@ -302,7 +302,7 @@ Vitest 使用 [Vite dev server](https://cn.vitejs.dev/guide/#browser-support)
302302- Safari >=15.4
303303- Edge >=88
304304
305- ## Running Tests
305+ ## 运行测试
306306
307307要使用 CLI 指定浏览器,请使用 ` --browser ` 标志后跟浏览器名称,如下所示:
308308
@@ -357,7 +357,7 @@ npx vitest --browser.headless
357357默认情况下Headless模式不可用。我们需要使用 [ ` playwright ` ] ( https://npmjs.com/package/playwright ) 或 [ ` webdriverio ` ] ( https://www.npmjs.com/package/webdriverio ) 提供程序来启用此功能。
358358:::
359359
360- ## Examples
360+ ## 例子
361361
362362一般情况下,我们不需要任何依赖来使用浏览器模式:
363363
@@ -367,7 +367,7 @@ import { page } from 'vitest/browser'
367367import { render } from ' ./my-render-function.js'
368368
369369test (' properly handles form inputs' , async () => {
370- render () // mount DOM elements
370+ render () // 挂载 DOM 元素
371371
372372 // 断言初始状态。
373373 await expect .element (page .getByText (' Hi, my name is Alice' )).toBeInTheDocument ()
@@ -402,7 +402,7 @@ test('properly handles form inputs', async () => {
402402``` ts
403403import { expect } from ' vitest'
404404import { page } from ' vitest/browser'
405- // element is rendered correctly
405+ // 元素是正确渲染
406406await expect .element (page .getByText (' Hello World' )).toBeInTheDocument ()
407407```
408408
@@ -411,7 +411,7 @@ Vitest 暴露了一个[上下文 API](/guide/browser/context),其中包含一
411411``` ts
412412import { page , userEvent } from ' vitest/browser'
413413await userEvent .fill (page .getByLabelText (/ username/ i ), ' Alice' )
414- // or just locator.fill
414+ // 或只用 locator.fill
415415await page .getByLabelText (/ username/ i ).fill (' Alice' )
416416```
417417
@@ -504,7 +504,7 @@ import { render } from 'vitest-browser-qwik'
504504import Greeting from ' ./greeting'
505505
506506test (' greeting appears on click' , async () => {
507- // renderSSR and renderHook are also available
507+ // renderSSR 和 renderHook 也是可用
508508 const screen = render (<Greeting />)
509509
510510 const button = screen .getByRole (' button' )
@@ -531,7 +531,7 @@ Vitest 并不支持所有开箱即用的框架,但我们可以使用外部工
531531
532532::: code-group
533533``` tsx [solid]
534- // based on @testing-library/solid API
534+ // 基于 @testing-library/solid API
535535// https://testing-library.com/docs/solid-testing-library/api
536536
537537import { render } from ' @testing-library/solid'
@@ -558,7 +558,7 @@ it('uses params', async () => {
558558})
559559```
560560``` ts [marko]
561- // based on @testing-library/marko API
561+ // 基于 @testing-library/marko API
562562// https://testing-library.com/docs/marko-testing-library/api
563563
564564import { render , screen } from ' @marko/testing-library'
@@ -591,7 +591,7 @@ test('renders a message', async () => {
591591import { vi } from ' vitest'
592592import * as module from ' ./module.js'
593593
594- vi .spyOn (module , ' method' ) // ❌ throws an error
594+ vi .spyOn (module , ' method' ) // ❌ 抛出错误
595595```
596596
597597为了解决这个限制,Vitest 在 ` vi.mock('./module.js') ` 中提供了 ` { spy: true } ` 选项。启用后,它会自动对模块里所有的导出进行监听,而不会像普通 mock 那样将它们替换成假的实现。
0 commit comments