Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@storybook/testing-library
Advanced tools
Instrumented version of Testing Library for Storybook Interactions
@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.
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();
Jest is a JavaScript testing framework maintained by Facebook. It provides a complete and easy-to-set-up JavaScript testing solution. While Jest does not integrate directly with Storybook, it can be used alongside Testing Library to test React components.
Enzyme is a JavaScript testing utility for React that makes it easier to assert, manipulate, and traverse your React components' output. Unlike @storybook/testing-library, Enzyme does not integrate with Storybook and uses a different approach for rendering and interacting with components.
Cypress is a front-end testing tool built for the modern web. It allows you to write end-to-end tests, integration tests, and unit tests. Cypress provides a different approach compared to @storybook/testing-library, focusing more on end-to-end testing rather than isolated component testing within Storybook.
Storybook integration for Testing Library, instrumented for use with the Interactions addon.
For documentation, check the Storybook docs
FAQs
Instrumented version of Testing Library for Storybook Interactions
The npm package @storybook/testing-library receives a total of 1,214,850 weekly downloads. As such, @storybook/testing-library popularity was classified as popular.
We found that @storybook/testing-library demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 31 open source maintainers collaborating on the project.
Did you know?
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.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.