/* eslint-disable */ import * as React from "react" import { mount } from "enzyme" import TestRenderer from "react-test-renderer" import Popconfirm from ".." class PopconfirmMounter extends React.Component { state = { visible: true, } private popconfirm: any render() { const { visible } = this.state return ( { if (options.target !== "confirm" && !bool) { this.setState({ visible: false }) } else { this.setState({ visible: true }) } }} popup="popup" ref={(popconfirm: any) => { if (popconfirm) { this.popconfirm = popconfirm return this.popconfirm } return null }} >
children
) } } describe("Popconfirm", () => { beforeEach(() => { jest.useFakeTimers() }) afterEach(() => { jest.useRealTimers() }) it("是否正确渲染", () => { const wrapper = TestRenderer.create( children ) expect(wrapper).toMatchSnapshot() }) it("是否能内部驱动", () => { const onVisibleChange = jest.fn() const wrapper = mount(
child
) wrapper.find("#child").at(0).simulate("click") expect(onVisibleChange).toHaveBeenCalledWith(true, {}) expect(wrapper.find("Popover").props().visible).toBe(true) const buttons = wrapper.find("button") buttons.at(0).simulate("click") expect(onVisibleChange).toHaveBeenCalledWith(false, { target: "cancel" }) expect(wrapper.find("Popover").props().visible).toBe(false) wrapper.find("#child").at(0).simulate("click") buttons.at(1).simulate("click") expect(onVisibleChange).toHaveBeenCalledWith(false, { target: "confirm" }) expect(wrapper.find("Popover").props().visible).toBe(false) }) it("是否能外部控制", () => { const wrapper = mount() const buttons = wrapper.find("button") buttons.at(0).simulate("click") expect(wrapper.find("Popover").props().visible).toEqual(false) wrapper.find("#children").at(0).simulate("click") expect(wrapper.find("Popover").props().visible).toEqual(true) buttons.at(1).simulate("click") expect(wrapper.find("Popover").props().visible).toEqual(true) }) })