0

我有的

我想要的是按下一个选择组件并在下拉菜单中选择一个项目,但我遇到了一些问题:

  1. 如果我尝试使用getByTestId,控制台会出现错误,因为testIDprop 不适用于 Select 组件,并且 testing-library 找不到该元素。

  2. 我不能在 Select 呈现的文本元素上使用fireEvent,因为会引发错误: Unable to find node on an unmounted component.

那么使用 Select 组件测试表单的正确方法是什么?

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

import PSEForm from './PSEForm' // Form with input and select elements

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(
    <PSEForm onSubmit={onSubmitMock} />,
  )

  // 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小猫和伊娃版

包裹 版本
@eva设计/eva 2.1.0
@ui-kitten/组件 5.1.0
4

0 回答 0