chore(test): rewritten dropdown button component test using rtl (#4714)

This commit is contained in:
Tharun Rajendran
2022-03-28 13:32:35 -05:00
committed by GitHub
parent d0ad059369
commit 70a44dc262
@@ -1,5 +1,5 @@
import React from "react";
import { mount } from "enzyme";
import { fireEvent, render, screen } from "@testing-library/react";
import { noop } from "lodash";
import { DropdownButton } from "./DropdownButton";
@@ -11,18 +11,14 @@ describe("DropdownButton - component", () => {
{ label: "btn1", onClick: noop },
{ label: "btn2", onClick: optionSpy },
];
const component = mount(
render(
<DropdownButton options={dropdownOptions}>New Button</DropdownButton>
);
component.find("button.dropdown-button").simulate("click");
expect(component.state().isOpen).toEqual(true);
fireEvent.click(screen.getByText("New Button"));
component
.find("li.dropdown-button__option")
.last()
.find("Button")
.simulate("click");
fireEvent.click(screen.getByRole("button", { name: "btn2" }));
expect(optionSpy).toHaveBeenCalled();
});
});