jest-styled-components

  • Version 7.4.0
  • Published
  • 54.1 kB
  • 1 dependency
  • MIT license

Install

npm i jest-styled-components
yarn add jest-styled-components
pnpm add jest-styled-components

Overview

Jest utilities for Styled Components

Index

Variables

variable styleSheetSerializer

const styleSheetSerializer: any;

    Functions

    function disableCSSCache

    disableCSSCache: () => void;
    • Disable CSS parse caching and clear the cache.

    function enableCSSCache

    enableCSSCache: () => void;
    • Enable CSS parse caching for toHaveStyleRule. Caches the parsed AST and reuses it when the stylesheet hasn't changed, avoiding redundant parsing across multiple assertions in the same test. Call in your test setup file.

    function resetStyleSheet

    resetStyleSheet: () => void;
    • Reset the styled-components stylesheet between tests. Called automatically via beforeEach when available. Call manually in Vitest non-globals mode or custom test setups.

    function setStyleRuleOptions

    setStyleRuleOptions: (options?: StyleRuleOptions) => void;
    • Configure global defaults for toHaveStyleRule. Settings apply to all subsequent assertions unless overridden per-call.

    Interfaces

    interface StyledComponentsSerializerOptions

    interface StyledComponentsSerializerOptions {}

      property addStyles

      addStyles?: boolean;
      • Whether to prepend CSS rules to the snapshot output. true

      property classNameFormatter

      classNameFormatter?: (index: number) => string;
      • Custom formatter for replacement class names. Receives a zero-based index and returns the placeholder string. (index) => c${index}

      interface StyleRuleOptions

      interface StyleRuleOptions {}

        property namespace

        namespace?: string;
        • A StyleSheetManager namespace string (e.g. '#app'). When set, the matcher automatically prepends this prefix to every expected selector.

        Namespaces

        namespace global

        namespace global {}

          namespace global.jest

          namespace global.jest {}

            interface AsymmetricMatcher

            interface AsymmetricMatcher {}

              property $$typeof

              $$typeof: Symbol;

                property sample

                sample?: string | RegExp | object | Array<any> | Function;

                  interface Matchers

                  interface Matchers<R, T> {}

                    method toHaveStyleRule

                    toHaveStyleRule: {
                    (property: string, value?: Value): R;
                    (property: string, value?: Value, options?: Options): R;
                    };
                    • Assert that a CSS property has the expected value on a styled component.

                      Parameter property

                      The CSS property name, e.g. 'color', 'background'.

                      Parameter value

                      The expected value. Accepts a string, RegExp, Jest asymmetric matcher, or undefined to assert the property is not set. Optional when used with .not.

                      Parameter options

                      Narrow the match to rules inside at-rules (media, supports), with specific selectors (modifier), or by raw CSS selector (selector).

                    interface Options

                    interface Options {}

                      property container

                      container?: string;
                      • Target rules within a specific @container at-rule, e.g. '(min-width: 400px)'.

                      property layer

                      layer?: string;
                      • Target rules within a specific @layer at-rule, e.g. 'utilities'.

                      property media

                      media?: string;
                      • Target rules within a specific @media at-rule, e.g. '(max-width: 640px)'. Whitespace around colons is normalized automatically.

                      property modifier

                      modifier?: string | ReturnType<typeof css>;
                      • Refine the selector used to match rules. Supports pseudo-selectors (:hover), combinators (> div), the & self-reference (&&, &.active), parent selectors (.parent &), and the styled-components css helper for component selectors.

                      property namespace

                      namespace?: string;
                      • Match rules prefixed by a StyleSheetManager namespace, e.g. '#app'.

                      property selector

                      selector?: string;
                      • Match rules by CSS selector string instead of by component class name. Useful for testing createGlobalStyle styles, e.g. { selector: 'body' }. When set, the component argument to toHaveStyleRule is ignored.

                      property supports

                      supports?: string;
                      • Target rules within a specific @supports at-rule, e.g. '(display: grid)'.

                      type Value

                      type Value = string | number | RegExp | AsymmetricMatcher | undefined;

                        Package Files (1)

                        Dependencies (1)

                        Dev Dependencies (27)

                        Peer Dependencies (1)

                        Badge

                        To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                        You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/jest-styled-components.

                        • Markdown
                          [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/jest-styled-components)
                        • HTML
                          <a href="https://www.jsdocs.io/package/jest-styled-components"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>