mercredi 4 septembre 2019

How to get the amount of the same components with equal prop

I'm trying to get how many components have same props in react testing. I map and array, then return a checkbox checked or not depending one condition. I render 5 checkboxes and check 3.

How can I verify if there are really 3 checkboxes checked?

props.services are all the possible services (a checkbox) and props.activeCoupon.services are all the checkboxes that are gonna be checked

import React from "react";
import Adapter from "enzyme-adapter-react-16";
import expect from "expect";
import { configure, shallow } from "enzyme";
import CouponsServices from "./CouponsServices";
import { Checkbox } from "react-bootstrap";

configure({ adapter: new Adapter() });

const props = {
  services: [
    {
      id: 1,
      name: "Service 1"
    },
    {
      id: 2,
      name: "Service 2"
    },
    {
      id: 3,
      name: "Service 3"
    },
    {
      id: 4,
      name: "Service 4"
    },
    {
      id: 5,
      name: "Service 5"
    }
  ],
  activeCoupon: {
    id: 1,
    code: "Code 1",
    startDate: "2018-02-01",
    endDate: "2018-02-28",
    services: [
      {
        id: 1,
        name: "Service 1"
      },
      {
        id: 3,
        name: "Service 3"
      },
      {
        id: 4,
        name: "Service 4"
      }
    ],
    value: 20,
    isPercent: false
  },
  setState: jest.fn()
};

describe("<CouponsServices />", () => {
  const wrapper = shallow(<CouponsServices {...props} />);
  it("lists all available services", () => {
    expect(wrapper.find(Checkbox).length).toEqual(props.services.length);
  });
});


Aucun commentaire:

Enregistrer un commentaire