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

jest-styled-components

Package Overview
Dependencies
Maintainers
4
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-styled-components

Jest utilities for Styled Components

  • 7.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
617K
decreased by-5.86%
Maintainers
4
Weekly downloads
 
Created

What is jest-styled-components?

jest-styled-components is a Jest utility for testing styled-components. It provides custom matchers to test the styles applied to your components, making it easier to ensure that your styled-components are rendered correctly.

What are jest-styled-components's main functionalities?

toHaveStyleRule

The `toHaveStyleRule` matcher allows you to check if a specific style rule is applied to a component. In this example, it verifies that the `Button` component has a `color` style rule set to `red`.

const styled = require('styled-components').default;
const { toHaveStyleRule } = require('jest-styled-components');
expect.extend({ toHaveStyleRule });

const Button = styled.button`
  color: red;
`;

// Test
it('should have red color', () => {
  const wrapper = mount(<Button />);
  expect(wrapper).toHaveStyleRule('color', 'red');
});

toMatchSnapshot

The `toMatchSnapshot` matcher allows you to take a snapshot of the rendered component and compare it to a previously saved snapshot. This is useful for ensuring that the component's styles have not changed unexpectedly.

const styled = require('styled-components').default;
const { toMatchSnapshot } = require('jest-styled-components');
expect.extend({ toMatchSnapshot });

const Button = styled.button`
  color: red;
`;

// Test
it('should match the snapshot', () => {
  const wrapper = mount(<Button />);
  expect(wrapper).toMatchSnapshot();
});

Other packages similar to jest-styled-components

FAQs

Package last updated on 12 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