akveo / akveo/react-native-ui-kitten

How to test select component with react-native-testing-library

Đang mở
#1,473 3 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
TypeScript
Star
10.7k
Fork
962
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

## 💬 Question

What I want is to press a [select](https://akveo.github.io/react-native-ui-kitten/docs/components/select/overview#select) component and select an especific option, so I'm having some problems:

1. If I try to use [getByTestId](https://callstack.github.io/react-native-testing-library/docs/api-queries#bytestid), console trown an error because `testID` prop doesn't apply for Select component, and testing-library can't found the element.

2. I can't use [fireEvent](https://callstack.github.io/react-native-testing-library/docs/api#fireevent) over a text element rendered by Select because an error is thrown: ` Unable to find node on an unmounted component.`

What I'm trying is this:

```typescript
import React from 'react'
import {fireEvent, render, waitFor} from '@tests/test-utils'

import PSEForm from './PSEForm'

test('Render a form with financial institution selector, legal id type selector, legal id number input and submit button', async () => {
const onSubmitMock = jest.fn()
const {getByTestId, getByText, debug} = render(
,
)

// get form inputs
const finantialInstitutionSelect = getByText(/selecciona tu banco/i) // press component
const legalIdSelect = getByText(/escoge un tipo de documento/i) // press component
const documentNumberInput = getByTestId('pse.textfield.legal-id') // input component
const buttonSubmit = getByText(/pagar/i) // button component

// fill the form and submit it
fireEvent.press(legalIdSelect) // this thrwon an error
})

So what would be the correct way to test a form with Select component?
```

## UI Kitten and Eva version

| Package | Version |
| ----------- | ----------- |
| @eva-design/eva | 2.1.0 |
| @ui-kitten/components | 5.1.0 |

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.