styled-components / jest-styled-components

🔧 💅 Jest utilities for Styled Components
MIT License
1.59k stars 145 forks source link

add snapshot options #375

Closed jantimon closed 2 years ago

jantimon commented 3 years ago

We are using jest-styled-components in a large codebase and it works perfectly.
However sometimes we would love to have more control over the snapshots generation.

This pr shows how a setStyleSheetSerializerOptions might be added which would allow:

Example usage:

import 'jest-styled-components';
import { setStyleSheetSerializerOptions } from 'jest-styled-components/serializer';

describe('style tests', () => {
  test('it renders correct styles for X', () => { 
    const { container } = render(<Button />) 
    expect(container.firstChild).toMatchSnapshot()})
  })
}) 

describe('other tests', () => {
  beforeEach(() => {
    setStyleSheetSerializerOptions({ addStyles: false })
  });
  test('it renders correct markup for case X', () => { 
    const { container } = render(<Button />) 
    expect(container.firstChild).toMatchSnapshot()})
  })
}) 

I am very open to feedback and would love to know what you think

vadim-sartakov commented 2 years ago

It would be really helpful to have this kind of control over serialization. Any ideas on when it's going to be released?

protoEvangelion commented 2 years ago

I need this as well. @probablyup any ideas when this could be released?