findByType not working on sdk 32

This test for a simple component works very well

import React from 'react'
import { Text, View } from 'react-native'
import { create } from 'react-test-renderer'

const onPress = jest.fn()

class Test extends React.Component {
  render() {
    return <View>
      <Text onPress={onPress}>Daniel</Text>
    </View>
  }
}

it('Should call onPress', () => {
  const component = create(<Test/>)
  const element = component.root.findByType(Text)
  element.props.onPress()
  expect(onPress).toBeCalled()
})

But if i change from View to ScrollView it does not work anymore

Error: No instances found with node type: “Component”

import React from 'react'
import { Text, ScrollView } from 'react-native'
import { create } from 'react-test-renderer'

const onPress = jest.fn()

class Test extends React.Component {
  render() {
    return <ScrollView>
      <Text onPress={onPress}>Daniel</Text>
    </ScrollView>
  }
}

it('Should call onPress', () => {
  const component = create(<Test/>)
  const element = component.root.findByType(Text)
  element.props.onPress()
  expect(onPress).toBeCalled()
})

Why? What can i do?

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.