C
C
ch-aqwer2018-02-14 11:12:21
React
ch-aqwer, 2018-02-14 11:12:21

Why is the click not working in the test?

Good afternoon! Please tell me why the test gives such an error?
In other similar components, similar tests, everything works fine, but here is an error.
The test itself

it('should trigger prop openAppModal when modal btn is clicked', () => {
    const props = {
      app: {
        id: '1',
      },
      selectedItem: {
        id: '1',
      },
      openAppModal: jest.fn(),
      onChange: jest.fn(),
      isLoading: false,
    };
    const enzymeWrapper = shallow(<AppItem {...props} />);
    enzymeWrapper.find('[data-test="delete-Flight"]').simulate('click');

    expect(props.openAppModal).toHaveBeenCalledTimes(1);
  });

Mistake
Method “simulate” is only meant to be run on a single node. 0 found instead.

      53 |     };
      54 |     const enzymeWrapper = shallow(<AppItem {...props} />);
    > 55 |     enzymeWrapper.find('[data-test="modal"]').simulate('click');

For tests, I use jest/enzyme, a react/redux project.
Thank you!
Component
import React from 'react';
import PropTypes from 'prop-types';
import _map from 'lodash/map';
import { pure } from 'recompose';

import FlightCard, {
  FlightCardContent,
  FlightCardDescription,
  FlightCardFlight,
  FlightCardInfo,
  FlightPlayer,
  FlightCardDeleteWrapper,
  FlightCardContentTop,
  FlightCardContentBottom,
} from 'App/components/FlightCard';
import { IconDelete, IconSetText, IconNewFlight } from 'App/components/Icons';

import {
  FormGroupSelect,
} from 'App/components/Form';

import Time from 'App/components/Time';
import BEM from 'App/utils/BEM';
import { appType, dynamicFlightType } from 'App/types';

const b = BEM('Flight-card');

const handleDeleteDynamicFlight = (
  Flight,
  selectDynamicFlight,
  openAppDeleteFlightModal,
) => {
  selectDynamicFlight(Flight);

  openAppDeleteFlightModal();
};

const isLoading = (
  Flight,
  selectedDynamicFlight,
  isEditingLocale,
) => (
  Flight.id === selectedDynamicFlight.id && isEditingLocale
);

const FlightItem= ({
                            app,
                            Flight,
                            onChange,
                            selectedDynamicFlight,
                            selectDynamicFlight,
                            openAppDeleteDynamicFlightModal,
                            openAppDynamicFlightSetTextModal,
                            openAppDynamicFlightSetFlightModal,
                            isEditingLocale,
                          }) => (
  <FlightCard>
    <FlightCardContent>
      <div>
        <FlightCardContentTop>
          <FlightCardDescription>
            {Flight.transcription}
          </FlightCardDescription>

          <FlightCardFlight className={b('Flight').toString()}>
            <div>
              <div>
                <span className={b('filename')}>{Flight.filename}</span>
              </div>
              <FlightPlayer
                app={app}
                Flight={Flight}
              />

              <div className={b('Flight-buttons')} />
            </div>
          </FlightCardFlight>
        </FlightCardContentTop>
        <FlightCardContentBottom>
          <button
            className="button is-text is-uppercase"
            onClick={() => handleDeleteDynamicFlight(
              Flight,
              selectDynamicFlight,
              openAppDeleteDynamicFlightModal,
            )}
            data-test="delete-Flight"
          >
            <IconDelete />
            DELETE
          </button>
        </FlightCardContentBottom>
      </div>
    </FlightCardContent>
    
  </FlightCard>
);

export default pure(FlightItem);

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question