Skip to content

Using the library with Styled Components #127

Closed
@Ingibjorg

Description

@Ingibjorg

Hi, thank you for a great testing library!
Is there any additional setup I need to do to make the snapshot testing work smoothly with [styled-components](https://github.com/styled-components/styled-components)?

The generated snapshots are not useful as they're missing the entire CSS.

Snapshot with react-test-renderer:

// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Component SubmitButton renders correctly 1`] = `
<View
  accessible={true}
  isTVSelectable={true}
  onResponderGrant={[Function]}
  onResponderMove={[Function]}
  onResponderRelease={[Function]}
  onResponderTerminate={[Function]}
  onResponderTerminationRequest={[Function]}
  onStartShouldSetResponder={[Function]}
  style={
    Object {
      "alignItems": "center",
      "backgroundColor": "#006a35",
      "borderColor": "rgba(0, 0, 0, 0)",
      "borderRadius": 24,
      "borderWidth": 1.5,
      "height": 48,
      "justifyContent": "center",
      "marginBottom": 40,
      "marginHorizontal": 36,
      "opacity": 1,
    }
  }
>
  <Text
    labelColor="#fff"
    style={
      Array [
        Object {
          "color": "#fff",
          "fontFamily": "UniversLTPro-65Bold",
          "fontSize": 12,
          "letterSpacing": 1,
          "lineHeight": 14,
        },
      ]
    }
  >
   
  </Text>
</View>
`;

Snapshot with react-native-testing-library:

// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Component SubmitButton renders correctly 1`] = `
Object {
  "output": <ForwardRef
    disabled={false}
    onPress={[Function]}
  >
    <ForwardRef
      labelColor="#fff"
    >
      
    </ForwardRef>
  </ForwardRef>,
}
`;

As you can see, the snapshot spits out a bunch of ForwardRef components and doesn't list the CSS so the snapshot test only shows props passed to components and is not really useful.

Is there any additional setup I need here or do we need to add support for this in react-native-testing-library or styled-components?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions