Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

927 B
Raw Blame
import type { SyntheticEvent } from "react";
import { describe, expect, it } from "vite-plus/test";
import { isOwnDomEvent } from "./is-own-dom-event";

const eventFor = (currentTarget: Element, target: EventTarget) =>
  ({ currentTarget, target }) as unknown as SyntheticEvent<Element>;

describe("isOwnDomEvent", () => {
  it("accepts events from the element and its DOM children", () => {
    const card = document.createElement("div");
    const chip = document.createElement("button");
    card.append(chip);

    expect(isOwnDomEvent(eventFor(card, card))).toBe(true);
    expect(isOwnDomEvent(eventFor(card, chip))).toBe(true);
  });

  it("rejects events that bubbled through a portal", () => {
    const card = document.createElement("div");
    const menuOption = document.createElement("div");
    document.body.append(card, menuOption);

    expect(isOwnDomEvent(eventFor(card, menuOption))).toBe(false);
  });
});