|
@@ -0,0 +1,34 @@
|
|
|
+import { render, fireEvent, waitFor } from "@testing-library/react";
|
|
|
+import DelayedButton from "../DelayedButton";
|
|
|
+
|
|
|
+global.setInterval = jest.fn();
|
|
|
+
|
|
|
+describe("DelayedButton", () => {
|
|
|
+ beforeEach(() => {
|
|
|
+ jest.resetAllMocks();
|
|
|
+ });
|
|
|
+
|
|
|
+ it("renders and matches snapshot", () => {
|
|
|
+ const { container } = render(<DelayedButton>Test</DelayedButton>);
|
|
|
+ expect(container.firstChild).toMatchSnapshot();
|
|
|
+ });
|
|
|
+
|
|
|
+ it("switches to a delay button when clicked", async () => {
|
|
|
+ // TODO
|
|
|
+ // let timerAdvance;
|
|
|
+ // setInterval.mockImplementation(fn => {
|
|
|
+ // timerAdvance = fn;
|
|
|
+ // });
|
|
|
+ const onEnd = jest.fn();
|
|
|
+ const { container, getByText, queryByText } = render(
|
|
|
+ <DelayedButton onEnd={onEnd}>Test</DelayedButton>
|
|
|
+ );
|
|
|
+ fireEvent.click(getByText("Test"));
|
|
|
+ await waitFor(() => expect(queryByText("Test")).not.toBeInTheDocument());
|
|
|
+ expect(container.firstChild).toMatchSnapshot();
|
|
|
+ // TODO
|
|
|
+ // timerAdvance();
|
|
|
+ // timerAdvance();
|
|
|
+ // expect(container.firstChild).toMatchSnapshot();
|
|
|
+ });
|
|
|
+});
|