Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@storybook/test

Package Overview
Dependencies
Maintainers
9
Versions
517
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@storybook/test

  • 8.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.9M
increased by2.74%
Maintainers
9
Weekly downloads
 
Created
Source

Storybook Test

The @storybook/test package contains utilities for testing your stories inside play functions.

Installation

Install the package by adding the @storybook/test dev dependency:

npm install -D @storybook/test
pnpm add -D @storybook/test
yarn add -D @storybook/test

Note that this package is not an addon, so you don't have to add it to your main.js/main.ts file.

Usage

The test package exports instrumented versions of @vitest/spy, @vitest/expect (based on chai), @testing-library/dom and @testing-library/user-event. The instrumentation makes sure you can debug those methods in the addon-interactions panel.

// Button.stories.ts
import { Button } from './Button';
import { within, userEvent, expect, fn } from '@storybook/test';

export default {
  component: Button,
  args: {
    onClick: fn(),
  },
};

export const Demo = {
  play: async ({ args, canvasElement }) => {
    const canvas = within(canvasElement);
    await userEvent.click(canvas.getByRole('button'));
    await expect(args.onClick).toHaveBeenCalled();
  },
};

Keywords

FAQs

Package last updated on 21 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc