F
F
fronter-up2018-02-22 18:04:09
Software testing
fronter-up, 2018-02-22 18:04:09

How to test modal window closing, react?

Good afternoon! Can you please tell me how to test the handleCloseModal method in the component?
The component itself

const TextModal = ({
  isOpen,
  isLoading,
  onClose,
  handleSubmit,
  onSubmit,
  update,
}) => {
  const handleCloseModal = () => {
    onClose();
    update()
  };
  return (
    <Modal
      isOpen={isOpen}
      handleClose={handleCloseModal}
    >
      <Form onSubmit={handleSubmit(onSubmit)}>
        <ModalBody>
          <Field
            name="text"
            component={FormGroupField}
            label="Text"
          />
        </ModalBody>
        <ModalFooter>
          <FormSubmit
            className="button is-primary"
            isLoading={isLoading}
          >
            Save
          </FormSubmit>
        </ModalFooter>
      </Form>
    </Modal>
  );
};

For tests I use jest / enzyme
In this case, the error
it('test closeModal', () => {
    const props = {
      isOpen: true,
      isLoading: false,
      change: jest.fn(),
      onSubmit: jest.fn(),
      onClose: jest.fn(),
      handleSubmit: jest.fn(),
    };

    const enzymeWrapper = shallow(<TextModal {...props} />);
    enzymeWrapper.instance().handleCloseModal();

    expect(props.onClose).toHaveBeenCalledTimes(1);
    expect(props.update).toHaveBeenCalledTimes(1);
  });

I will be grateful for your help!

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