Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
V

vitest-preview

> 前端框架
Open source

Debug your Vitest tests. Effortlessly. ⚡️

391 stars0 likes1 views
WebsiteGitHub

About

Debug your Vitest tests. Effortlessly. ⚡️

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 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

TypeScriptdebugfrontendproductivityreact

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category前端框架
PricingOpen source

> Related tools

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