dimanche 24 janvier 2021

React Js jest ezyme using test for checkbox simulation

I need to simulate checkbox inside Input Tag using jest enzyme. Below my code is there how can I do please anyone help. how to simulate checkbox check(tick)

<Table>
            <thead>
              <tr>
                <th className="text-left">Active</th>
                <th>Display Name</th>
                <th>Type</th>
                <th className="text-center">Associated Sensors</th>
                <th className="text-center">Battery</th>
                <th className="text-center">Network Signal</th>
                <th className="text-right">Information</th>
              </tr>
            </thead>
            <tbody>
              {filteredSensors.map(d => (
                <tr key={key(d)}>
                  <td className="text-left">
                    <FormGroup check>
                      <Label check>
                        **<Input
                          type="checkbox"
                          name={d.sensorId}
                          id={d.sensorId}
                          checked={isDeviceChecked(d.sensorId)}
                          onChange={handleDeviceChange}
                        />**
                        <span className="form-check-sign">
                          <span className="check" />
                        </span>
                      </Label>
                    </FormGroup>
                  </td>
                  <td>{d.getDisplayName()}</td>
                  <td>{d.type}</td>
                  <td className="text-center">{d.dataObj ? Object.keys(d.dataObj).length : 0}</td>
                  <td className="text-center">{d.voltage}</td>
                  <td className="text-center">{d.signal}</td>
                  <td className="text-right">
                    <Button className="btn-icon btn-link" color="default" size="sm">
                      <FontAwesomeIcon icon="info-circle" />
                    </Button>
                    {` `}
                    <Button className="btn-icon btn-link" color="default" size="sm">
                      <FontAwesomeIcon icon="cog" />
                    </Button>
                  </td>
                </tr>
              ))}
            </tbody>
          </Table>

This is my testing script code unable to simulate the check box inside of Input tag. Below my code is there how can I do please anyone help. how to simulate checkbox check(tick)

test('checkbox', () => {
   

  const wr = mount(<Devices />);

  const checkbox = wr.find('Table').find('Input[type="checkbox"]');
  const d = wr.find('tbody');
  console.log(d.children().at(0));
  // checkbox.at(0).simulate('change', { target: { checked: true } });/
  d.children()
    .at(0)
    .simulate('change', { target: { checked: true } });
  // wr.update();
  // expect(checkbox.props().checked).tbBe(true);
  expect(d.childAt(0))
});

Aucun commentaire:

Enregistrer un commentaire