jest-styled-components
- Version 7.4.0
- Published
- 54.1 kB
- 1 dependency
- MIT license
Install
npm i jest-styled-componentsyarn add jest-styled-componentspnpm add jest-styled-componentsOverview
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
beforeEachwhen 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
StyleSheetManagernamespace 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 {}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
undefinedto 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
@containerat-rule, e.g.'(min-width: 400px)'.
property layer
layer?: string;Target rules within a specific
@layerat-rule, e.g.'utilities'.
property media
media?: string;Target rules within a specific
@mediaat-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-componentscsshelper for component selectors.
property namespace
namespace?: string;Match rules prefixed by a
StyleSheetManagernamespace, e.g.'#app'.
property selector
selector?: string;Match rules by CSS selector string instead of by component class name. Useful for testing
createGlobalStylestyles, e.g.{ selector: 'body' }. When set, the component argument totoHaveStyleRuleis ignored.
property supports
supports?: string;Target rules within a specific
@supportsat-rule, e.g.'(display: grid)'.
type Value
type Value = string | number | RegExp | AsymmetricMatcher | undefined;Package Files (1)
Dependencies (1)
Dev Dependencies (27)
- @arethetypeswrong/cli
- @babel/core
- @babel/plugin-transform-flow-strip-types
- @babel/preset-env
- @babel/preset-react
- @biomejs/biome
- @cfaester/enzyme-adapter-react-18
- @changesets/changelog-git
- @changesets/cli
- @testing-library/react
- babel-jest
- enzyme
- enzyme-adapter-preact-pure
- enzyme-to-json
- husky
- jest
- jest-environment-jsdom
- lint-staged
- preact
- preact-render-to-json
- pretty-format
- publint
- react
- react-dom
- react-native
- react-test-renderer
- styled-components
Peer Dependencies (1)
Badge
To add a badge like this oneto 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[](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>
- Updated .
Package analyzed in 2652 ms. - Missing or incorrect documentation? Open an issue for this package.
