You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vitest Browser模式运行测试时组件无法显示求助

问题:@testing-library/react渲染的组件在Vitest浏览器测试中不显示

我已下载并配置了@vitest/browser与webdriverio,测试可在Chrome浏览器中正常运行并显示测试结果,但通过@testing-library/react渲染的组件并未在浏览器中显示。

测试代码

import { render, screen, waitFor } from '@testing-library/react'

it('whatever', async () => {
  render(<h1>dude</h1>)
})

部分Vitest配置

const vitestConfig: { test: ViteConfigWithVitest['test'] } = {
  test: {
    browser: {
      provider: 'webdriverio',
      enabled: true,
      name: 'chrome',
    },

...

  plugins: [
    nxViteTsPaths(),
    react(),
    vanillaExtractPlugin(),
    topLevelAwait({
      // 每个chunk模块中顶层await promise的导出名称
      promiseExportName: '__tla',
      // 为每个chunk模块生成顶层await promise导入名称的函数
      promiseImportName: (i) => `__tla_${i}`,
    }),
  ],
}

浏览器仅显示测试结果无组件

内容的提问来源于stack exchange,提问作者Jonathan Tuzman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 20:22:34