Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] autoPreview mode #21

Open
tsirlucas opened this issue Feb 25, 2023 · 1 comment
Open

[Feature request] autoPreview mode #21

tsirlucas opened this issue Feb 25, 2023 · 1 comment
Labels
new feature New feature request

Comments

@tsirlucas
Copy link

Is your feature request related to a problem? Please describe.

Not related to a problem.

Describe the solution you'd like

A way to setup autoPreview.

Describe how should we implement this feature

Same functionality as jest-preview

Describe alternatives you've considered

Attempt to setup jest-preview with vitest,

Additional context

N/A

@nvh95 nvh95 added the new feature New feature request label Feb 28, 2023
@BrandonGoren
Copy link

BrandonGoren commented Mar 28, 2023

I got this working in a vitest/react-testing-library app using the following method. It's an alternative to patching it, which is what jest-preview does.

  1. Turn off automatic cleanup in react-testing-library
  2. Add the following to your setupTests.ts file (or equivalent under setupFiles):
import { debug } from 'vitest-preview';
import { cleanup } from '@testing-library/react';

afterEach(context => {
  // Run vitest-preview's debug if the test fails
  if (context?.meta?.result?.state === 'fail') {
    debug();
  }
  // Clean up react-testing-library. We need to manually do this because we
  // turn off the automatic teardown in the vite.config.
  // This needs to happen after vitest-preview.
  cleanup();
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature request
Projects
None yet
Development

No branches or pull requests

3 participants