UNPKG

@embrace-io/react-native

Version:
49 lines (48 loc) 2.45 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const react_native_1 = require("@testing-library/react-native"); const useEmbraceIsStarted_1 = require("./useEmbraceIsStarted"); const mockIsStarted = jest.fn(); jest.mock("../EmbraceManagerModule", () => ({ EmbraceManagerModule: { isStarted: () => mockIsStarted(), }, })); describe("useEmbraceIsStarted", () => { afterEach(() => { jest.clearAllMocks(); }); it("should return if the Native SDK is started", () => __awaiter(void 0, void 0, void 0, function* () { mockIsStarted.mockResolvedValue(true); const { result } = (0, react_native_1.renderHook)(useEmbraceIsStarted_1.useEmbraceIsStarted); expect(result.current).toBe(null); yield (0, react_native_1.waitFor)(() => { expect(result.current).toBe(true); }); })); it("should return if the Native SDK is not started", () => __awaiter(void 0, void 0, void 0, function* () { mockIsStarted.mockResolvedValue(false); const { result } = (0, react_native_1.renderHook)(useEmbraceIsStarted_1.useEmbraceIsStarted); expect(result.current).toBe(null); yield (0, react_native_1.waitFor)(() => { expect(result.current).toBe(false); }); })); it("should handle getting an error when checking if the Native SDK is started", () => __awaiter(void 0, void 0, void 0, function* () { mockIsStarted.mockRejectedValue("some error"); const { result } = (0, react_native_1.renderHook)(useEmbraceIsStarted_1.useEmbraceIsStarted); expect(result.current).toBe(null); yield (0, react_native_1.waitFor)(() => { expect(result.current).toBe(false); }); })); });