百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
V

vitest-preview

> 前端框架
开源

轻松地调试您的 Vitest 测试。 ⚡️

391 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

轻松地调试您的 Vitest 测试。 ⚡️

Vitest Preview

Debug your Vitest tests. Effortlessly. ⚡️

Try Vitest Preview Online. No downloads needed!

Why vitest-preview

When writing tests, we usually have to debug by reading the cryptic HTML output on the terminal. Sometimes, they are too complicated to visualize the UI in our heads. vitest-preview previews your Vitest tests right in a browser, then you can see your actual UI visually. You can write tests and watch rendered output changes accordingly. Vitest Preview lets you concentrate on tests in the "real world" rather than deciphering HTML code.

vitest-preview is built on top of Vite, it's blazing fast and easy to use.

vitest-preview is a younger sibling of jest-preview with the same idea and to solve the same problem. If you are writing tests using Jest, give it a try.

Features

  • Visualize your testing UI in an external browser in milliseconds.
  • Auto reloads the browser when debug() is executed.
  • Automatic debugging with watch() function that observes DOM changes.
  • Fully support CSS
  • Support viewing images.

Installation

bash
npm install --save-dev vitest-preview
# Or
yarn add -D vitest-preview
pnpm add -D vitest-preview

Configuration

Process CSS

You need to configure vitest to process CSS by:

diff
// vite.config.js
export default defineConfig({
  test: {
+    css: !process.env.CI, // We usually don't want to process CSS in CI
  },
});

You might want to import your CSS global files in setupFiles:

diff
// vite.config.js
export default defineConfig({
  test: {
+    setupFiles: './src/test/setup.ts',
  },
});
diff
// src/test/setup.ts
+import './global.css';
+import '@your-design-system/css/dist/index.min.css';
+import 'bootstrap/dist/css/bootstrap.min.css';

Add script vitest-preview

vitest-preview has a CLI that opens Vitest Preview Dashboard where you can preview your tests' UI. You can update your package.json to add a script for more convenience:

json
"scripts": {
  "vitest-preview": "vitest-preview"
},

Usage

Manual Debugging

Put debug() wherever you want to see the UI in your tests.

diff
+import { debug } from 'vitest-preview';

describe('App', () => {
  it('should work as expected', () => {
    render();
+    debug();
  });
});

Automatic Debugging with watch()

Use watch() to automatically capture DOM changes without manually calling debug().

diff
+import { watch } from 'vitest-preview';

describe('App', () => {
+  let stopWatching;
+  beforeEach(() => {
+    stopWatching = watch();
+  });
+  afterEach(() => {
+    stopWatching();
+  });

  it('should work as expected', async () => {
    render();
    await userEvent.click(screen.getByText('Increment'));
    // DOM changes are automatically captured
  });
});

Open the Vitest Preview Dashboard by running the CLI command (updated in Configuration):

bash
npm run vitest-preview
# Or
yarn vitest-preview
pnpm vitest-preview

Then execute your tests that contain debug(). You will see the UI of your tests at http://localhost:5006.

Examples

  • react-testing-library
  • @vue/test-utils

Is there a similar library for Jest

Yes, it is. It's Jest Preview.

Star history

Contributing

Please see the contribution guide at CONTRIBUTING.md.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Hung Viet Nguyen

Andre

René Wang

Nils Knappmeier

Tarjei Huse

Truong Nguyen

Heath C

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT

Support

If you like the project, please consider supporting it by giving a ⭐️ to encourage the author.

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScriptdebugfrontendproductivityreact

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类前端框架
定价开源

> 相关工具

R
React
用于构建用户界面的 JavaScript 库
V
Vue.js
渐进式 JavaScript 框架
N
Next.js
基于 React 的全栈 Web 框架