1.0.4 • Published 4 years ago

ignore-styled-components-theme v1.0.4

Weekly downloads
4
License
MIT
Repository
github
Last release
4 years ago

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

PropertyTypeDefault ValueDescription
defaultPropsbooleantrueremoves themes in prop that are the same as default props
aggressivebooleanfalseremoves themes in prop if the component is a styled component
themesobject[][]removes themes in prop if they are the same as one in the given array
1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago