/* eslint-disable no-global-assign */ /* eslint-disable @typescript-eslint/no-empty-function */ import { Provider, createStore } from "@frontity/connect"; /** * @jest-environment jsdom */ import TestRenderer from "react-test-renderer"; import useInView from "@frontity/hooks/use-in-view"; import Iframe from "../iframe"; jest.mock("@frontity/hooks/use-in-view", () => ({ __esModule: true, default: jest.fn(), })); describe("Iframe", () => { const mockedUseInView = useInView as jest.MockedFunction; beforeEach(() => { delete (HTMLIFrameElement as any).prototype.loading; Object.defineProperty(window, "IntersectionObserver", { writable: true, value: jest.fn(), }); }); afterEach(() => { mockedUseInView.mockReset(); }); test('works when loading === "eager"', () => { const loading: "lazy" | "eager" = "eager"; const props = { title: "Iframe title", src: "https://iframe-src.com/iframe", className: "fake-class-name", height: 500, loading, }; mockedUseInView.mockReturnValue({ ref: () => {}, inView: false, supported: true, }); const result = TestRenderer.create(