testing-library/jest-native

toHaveStyle does not find all styles

mikinw opened this issue · 1 comments

Describe the feature you'd like:

I have the same (similar) issue. There is a component:
<MaterialIcons testID="iconID" style={[styles.icon, {backgroundColor: '#ff0000'}]} />

the styles.js looks like this:
icon: { color: Colors.paleWhite, },

When I create a snapshot, it gives me this:
... <Text allowFontScaling={false} style={ Array [ Object { "color": undefined, "fontSize": 22, }, Array [ Object { "color": "#EDEDED", "margin": 15, }, Object { "backgroundColor": "#7692DD", }, ], Object { "fontFamily": "Material Icons", "fontStyle": "normal", "fontWeight": "normal", }, Object {}, ] } testID="iconID" >

But when I try to match against a style expect(sut.queryByTestId('iconID')).toHaveStyle([ {fontFamily: 'Material Icons', backgroundColor: '#ff0000'}, ]);

It can't find backgroundColor (which is one more level in). It does find fontFamily.

Suggested implementation:

Search for styles in the inner arrays also

Describe alternatives you've considered:

Teachability, Documentation, Adoption, Migration Strategy:

I just realised, there is is a quite recent new release (3.0.3. for the record), which solves the issue.
Thanks for the quick fix ;-).