我正在尝试获得多少组件在反应测试中具有相同的道具。我映射并排列数组,然后根据一个条件返回是否已选中的复选框。我渲染5个复选框并选中3。
如何验证是否真的选中了3个复选框?
props.services
是所有可能的服务(一个复选框),而props.activeCoupon.services
是所有将被选中的复选框
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);
});
});