Writing Tests


For a component library to be stable, it must be testable and tested.

Test Types

Component (Unit) Tests

  • Tests run using jest.
  • These tests focus on component behavior and don't require visual rendering.
  • Each component has an associated test file with a .spec.tsx extension (for example, ComponentName.spec.tsx).
  • Each component has a driver, named ComponentName.uni.driver.ts.

Writing a unit test (example)

Copy

Visual Testing

Terminology

  • Storybook: A playground for displaying React components with a navigation sidebar.
  • Sled: A tool for visual testing in Storybook.

FAQ

Q: How do I create visual test files?

A: Create a new file MyComponent/test/MyComponent.visual.tsx:

Copy

Q: What do I test in visual tests?

A: Styling variations in different states (for example, props like: size, skin, error message...).


Q: How do I test interactions in visual tests?

A: For asynchronous actions (for example, waiting for a tooltip to appear), use Sled e2e tests.

Warning: Interactions that aren't immediate (like animations) can cause flaky tests.


Q: How to run visual tests locally?

Copy

or

Copy

Q: How can I update a baseline if I see a diff?

A: There are two ways you can accept a baseline.

  1. Run locally:
Copy

or

Copy
  1. In the pull request when the build fails, open the build log (Falcon), find the link to Sheshesh, and accept the baseline there.

Q: How can I debug a component that has been rendered into a snapshot?

A: Start Storybook testing environment to see your snapshots live:

Copy

or

Copy

Once the local server is running, open it in your browser and navigate to the component you want to debug. Then, in code, find the snapshot-generating test and work with it to find a solution to your problem.

Sled E2E tests

  1. These tests use real browser APIs (for example, position calculations, hovering, styling).
  2. Tests run with sled using Puppeteer in Chrome.
  3. Tests are defined with a .sled.spec.ts extension (for example, ComponentName.sled.spec.ts), located in packages/wix-design-system/sled/tests/__storybook-e2e-tests__/.

Running Tests

Unit Tests

  1. Single run:
Copy

or

Copy
  1. Watch mode:
Copy

or

Copy

Debugging

In watch mode, use jest's interactive mode by pressing p and typing the name of the test.

Visual Tests

Copy

or

Copy

Sled E2E tests

Copy

or

Copy





Last updated: 26 October 2026

Did this help?