小编Ric*_*Hpa的帖子

不使用 testid 测试 Material ui Select 组件

我目前正在表单上使用 Material UI 和 React-testing-library。我有一个由对象数组填充的选择。

import React, { useState } from 'react';
import { Select, MenuItem, FormControl, InputLabel } from '@material-ui/core';

const options = [
  {
    label: 'Example 1',
    value: 123456789,
  },
  {
    label: 'Example 2',
    value: 987654321,
  },
];

const SelectTesting = () => {
  const [value, setValue] = useState('');

  const handleChange = (event) => {
    setValue(event.target.value);
  };

  return (
    <FormControl variant="outlined" fullWidth>
      <InputLabel id="selectedOptionLabel">Select an Option</InputLabel>
      <Select
        labelId="selectedOptionLabel"
        id="selectedOption"
        value={value}
        onChange={handleChange}
        label="Select an Option"
      >
        {options.map((option) => ( …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs material-ui react-testing-library

5
推荐指数
1
解决办法
5374
查看次数