Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
fix: resolve renderHook related test errors (#2839)
Browse files Browse the repository at this point in the history
  • Loading branch information
goga-m committed Sep 18, 2020
1 parent 5e8e46c commit 231e889
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 16 deletions.
@@ -1,9 +1,9 @@
import { Profile, ReadWriteWallet } from "@arkecosystem/platform-sdk-profiles";
import { renderHook } from "@testing-library/react-hooks";
import { act, renderHook } from "@testing-library/react-hooks";
import { Form } from "app/components/Form";
import React from "react";
import { useForm } from "react-hook-form";
import { act, env, fireEvent, getDefaultProfileId, renderWithRouter, screen, waitFor } from "utils/testing-library";
import { env, fireEvent, getDefaultProfileId, renderWithRouter, screen, waitFor } from "utils/testing-library";

import { AuthenticationStep } from "./AuthenticationStep";

Expand All @@ -25,11 +25,11 @@ describe("AuthenticationStep", () => {
it("should request mnemonic", async () => {
jest.spyOn(wallet, "isSecondSignature").mockReturnValueOnce(false);

const { result } = renderHook(() => useForm({ mode: "onChange" }));
const { result } = renderHook(() => useForm({ mode: "onChange", shouldUnregister: false }));
const { asFragment } = renderWithRouter(<Component form={result.current} />);

await waitFor(() => expect(screen.queryByTestId("AuthenticationStep__second-mnemonic")).toBeNull());
expect(screen.queryByTestId("AuthenticationStep__mnemonic")).toBeInTheDocument();
await waitFor(() => expect(screen.queryByTestId("AuthenticationStep__mnemonic")).toBeInTheDocument());

act(() => {
fireEvent.input(screen.getByTestId("AuthenticationStep__mnemonic"), {
Expand All @@ -39,18 +39,18 @@ describe("AuthenticationStep", () => {
});
});

expect(result.current.getValues()).toEqual({ mnemonic: "my mnemonic" });
await waitFor(() => expect(result.current.getValues()).toEqual({ mnemonic: "my mnemonic" }));
expect(asFragment()).toMatchSnapshot();
});

it("should request mnemonic and second mnemonic", () => {
it("should request mnemonic and second mnemonic", async () => {
jest.spyOn(wallet, "isSecondSignature").mockReturnValueOnce(true);

const { result } = renderHook(() => useForm({ mode: "onChange" }));
const { result } = renderHook(() => useForm({ mode: "onChange", shouldUnregister: false }));
const { asFragment } = renderWithRouter(<Component form={result.current} />);

expect(screen.queryByTestId("AuthenticationStep__second-mnemonic")).toBeInTheDocument();
expect(screen.queryByTestId("AuthenticationStep__mnemonic")).toBeInTheDocument();
await waitFor(() => expect(screen.queryByTestId("AuthenticationStep__mnemonic")).toBeInTheDocument());
await waitFor(() => expect(screen.queryByTestId("AuthenticationStep__second-mnemonic")).toBeInTheDocument());

act(() => {
fireEvent.input(screen.getByTestId("AuthenticationStep__mnemonic"), {
Expand All @@ -68,19 +68,24 @@ describe("AuthenticationStep", () => {
});
});

expect(result.current.getValues()).toEqual({ mnemonic: "my mnemonic", secondMnemonic: "my second mnemonic" });
await waitFor(() =>
expect(result.current.getValues()).toEqual({
mnemonic: "my mnemonic",
secondMnemonic: "my second mnemonic",
}),
);
expect(asFragment()).toMatchSnapshot();
});

it("should show only ledger confirmation", () => {
it("should show only ledger confirmation", async () => {
jest.spyOn(wallet, "isLedger").mockReturnValueOnce(true);

const { result } = renderHook(() => useForm({ mode: "onChange" }));
const { result } = renderHook(() => useForm({ mode: "onChange", shouldUnregister: false }));
const { asFragment } = renderWithRouter(<Component form={result.current} />);

expect(screen.queryByTestId("LedgerConfirmation-description")).toBeInTheDocument();
expect(screen.queryByTestId("AuthenticationStep__second-mnemonic")).toBeNull();
expect(screen.queryByTestId("AuthenticationStep__mnemonic")).toBeNull();
await waitFor(() => expect(screen.queryByTestId("LedgerConfirmation-description")).toBeInTheDocument());
await waitFor(() => expect(screen.queryByTestId("AuthenticationStep__mnemonic")).toBeNull());
await waitFor(() => expect(screen.queryByTestId("AuthenticationStep__second-mnemonic")).toBeNull());

expect(asFragment()).toMatchSnapshot();
});
Expand Down
Expand Up @@ -7,8 +7,9 @@ import { Form } from "app/components/Form";
import React from "react";
import { useForm } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { act } from "react-test-renderer";
import secondSignatureFixture from "tests/fixtures/coins/ark/transactions/second-signature-registration.json";
import { act, env, fireEvent, getDefaultProfileId, render, screen, waitFor } from "utils/testing-library";
import { env, fireEvent, getDefaultProfileId, render, screen, waitFor } from "utils/testing-library";

import { translations as transactionTranslations } from "../../i18n";
import { SecondSignatureRegistrationForm } from "./SecondSignatureRegistrationForm";
Expand Down Expand Up @@ -70,6 +71,7 @@ describe("SecondSignatureRegistrationForm", () => {

it("should set fee", async () => {
const { result } = renderHook(() => useForm());

result.current.register("fee");

render(<Component form={result.current} onSubmit={() => void 0} />);
Expand Down

0 comments on commit 231e889

Please sign in to comment.