UNPKG

@ledgerhq/live-common

Version:
48 lines 1.74 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * @jest-environment jsdom */ const react_1 = require("@testing-library/react"); const usePageState_1 = require("./usePageState"); describe("usePageState", () => { it("returns the correct page state", () => { const swapTransaction = { swap: { from: { amount: { isZero: () => true, }, }, rates: { status: "success", }, isMaxLoading: false, }, }; let swapError = undefined; const { result, rerender } = (0, react_1.renderHook)(() => (0, usePageState_1.usePageState)(swapTransaction, swapError)); // Initial render expect(result.current).toBe("initial"); // Rerender with rates loading swapTransaction.swap.rates.status = "loading"; rerender(); expect(result.current).toBe("loading"); // Rerender with rates error swapTransaction.swap.rates.status = "error"; rerender(); expect(result.current).toBe("initial"); // Rerender with empty error message and data loaded swapTransaction.swap.rates.status = "success"; swapError = { message: "" }; rerender(); expect(result.current).toBe("empty"); // Rerender with from field is zero and data loaded swapError = undefined; if (swapTransaction.swap.from.amount) swapTransaction.swap.from.amount.isZero = () => true; rerender(); expect(result.current).toBe("initial"); }); }); //# sourceMappingURL=usePageState.test.js.map