ignore-styled-components-theme
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

Ignore Styled Components Theme

This snapshot serializer tries it's best to hide the theme property for styled components in snapshot tests.

Usage

In your jest config add this as a serailizer

module.exports = {
    ...,
    snapshotSerializers: [
        ...,
        "ignore-styled-components-theme"
    ]
}

Complex Usage

You can customize the behavior of this serializer by creating a javascript file that imports the createSerializer. This way you can still have snapshots when themes are actually being tested.

In project root testSetup/ignore-styled-components-theme.js

const createSerializer = require('ignore-styled-components-theme/createSerializer');
module.exports = createSerializer({ aggressive: true });

jest.config.js

module.exports = {
    ...,
    snapshotSerializers: [
        ...,
        "<rootDir>/testSetup/ignore-styled-components-theme.js"
    ]
}

Nuclear

If you do not want to show theme props in snapshots at all you can use the nuclear option.

testSetup/ignore-styled-components-theme.js

const createSerializer = require('ignore-styled-components-theme/createSerializer');
module.exports = createSerializer('nuclear');

API

Property Type Default Value Description
defaultProps boolean true removes themes in prop that are the same as default props
aggressive boolean false removes themes in prop if the component is a styled component
themes object[] [] removes themes in prop if they are the same as one in the given array

Package Sidebar

Install

npm i ignore-styled-components-theme

Weekly Downloads

0

Version

1.0.4

License

MIT

Unpacked Size

5.45 kB

Total Files

6

Last publish

Collaborators

  • davidpark4393