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

@storybook/testing-library

Package Overview
Dependencies
Maintainers
31
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@storybook/testing-library

Instrumented version of Testing Library for Storybook Interactions

  • 0.2.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.4M
increased by0.2%
Maintainers
31
Weekly downloads
 
Created

What is @storybook/testing-library?

@storybook/testing-library is a package that integrates Storybook with Testing Library, allowing you to test your components in isolation within the Storybook environment. It provides utilities to render and interact with your components in a way that mimics how users would interact with them.

What are @storybook/testing-library's main functionalities?

Render Storybook Stories

This feature allows you to render a Storybook story directly in your tests. You can then use Testing Library queries to interact with the rendered component and make assertions.

import { render } from '@storybook/testing-library';
import { MyComponent } from './MyComponent.stories';

const { getByText } = render(<MyComponent />);
expect(getByText('Hello World')).toBeInTheDocument();

Interaction Testing

This feature allows you to simulate user interactions with your components, such as clicks, typing, and other events. You can then assert the expected changes in the component's state or output.

import { render, fireEvent } from '@storybook/testing-library';
import { MyButton } from './MyButton.stories';

const { getByRole } = render(<MyButton />);
const button = getByRole('button');
fireEvent.click(button);
expect(button).toHaveTextContent('Clicked');

Snapshot Testing

This feature allows you to create snapshots of your components as they are rendered in Storybook. You can use these snapshots to ensure that your components' output does not change unexpectedly.

import { render } from '@storybook/testing-library';
import { MyComponent } from './MyComponent.stories';
import { create } from 'react-test-renderer';

const tree = create(render(<MyComponent />)).toJSON();
expect(tree).toMatchSnapshot();

Other packages similar to @storybook/testing-library

FAQs

Package last updated on 02 Oct 2023

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