testing-library/jest-native

toHaveStyle breaks if style is a nested array

felippepuhle opened this issue · 2 comments

  • react-native or expo: react-native
  • @testing-library/react-native version: 11.0.0
  • jest-preset: react-native
  • react-native version: 0.68.2
  • node version: 16

Problem description:

Problem was introduced on v4.0.11, after removing ramda.

Suggested solution:

Keep going deep when merging styles, or maybe using StyleSheet.flatten

Reproduction:

describe('toHaveStyle tests', () => {
  it('success', () => {
    const { getByText } = render(
      <Text style={[{ color: 'blue' }, [{ color: 'red' }]]}>Hey</Text>
    )

    expect(getByText('Hey')).toHaveStyle({
      color: 'red',
    })
  })

  it('fail', () => {
    const { getByText } = render(
      <Text style={[{ color: 'blue' }, [[{ color: 'red' }]]]}>Hey</Text>
    )

    expect(getByText('Hey')).toHaveStyle({
      color: 'red',
    })
  })
})

Can you help us fix this issue by submitting a pull request?

I can look at it during my weekends, most likely on the next one

@felippepuhle Could you submit a PR, preferably using StyleSheet.flatten?

@felippepuhle Could you submit a PR, preferably using StyleSheet.flatten?

def! I'll push one later