Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { useIVI } from "ivi-jest";
const ivi = useIVI();
describe("getFunctionName", () => {
function wrap(fn: Function): Function {
return fn;
}
test("basic name", () => {
function A() { /* */ }
expect(ivi.getFunctionName(A)).toBe("A");
});
test("displayName", () => {
function A() { /* */ }
A.displayName = "B";
import { useResetDOM, useResetModules, useIVI } from "ivi-jest";
useResetDOM();
useResetModules();
const ivi = useIVI();
describe(`Event Handler`, () => {
function handler(ev: any): void {
// Event handler...
}
test(`event dispatcher should be assigned`, () => {
const h = ivi.onClick(handler);
expect(h.d.s).toBe(ivi.CLICK_EVENT);
});
test(`event handler should be assigned`, () => {
const h = ivi.onClick(handler);
expect(h.h).toBe(handler);
});
describe("SVG", () => {
const ivi = useIVI();
const s = useSVG();
const r = (op: Op) => t.render(op, root()).domNode!;
describe("mount", () => {
test("circle", () => {
const n = r(s.circle());
expect(n.namespaceURI).toBe(ivi.SVG_NAMESPACE);
expect(n).toMatchSnapshot();
expect(domOps()).toMatchSnapshot();
});
});
});
});
import { useIVI, useMockFn } from "ivi-jest";
const ivi = useIVI();
describe("RepeatableTaskList", () => {
const t = useMockFn((fn) => fn.mockReturnValue(true));
const f = useMockFn((fn) => fn.mockReturnValue(false));
test("run one task", () => {
ivi.runRepeatableTasks([f]);
expect(f).toHaveBeenCalledTimes(1);
});
test("run two tasks", () => {
ivi.runRepeatableTasks([f, f]);
expect(f).toHaveBeenCalledTimes(2);
});
test("run one task twice", () => {
import { useResetDOM, useDOMElement, useIVI, useHTML, useTest } from "ivi-jest";
import { Op } from "ivi";
useResetDOM();
const root = useDOMElement();
const ivi = useIVI();
const h = useHTML();
const t = useTest();
const input = (value: boolean, className?: string) => h.input(className, { autofocus: ivi.AUTOFOCUS(value) });
const r = (op: Op) => t.render(op, root()).domNode;
describe("attribute directive AUTOFOCUS", () => {
describe("mount", () => {
test("true", () => {
const n = r(input(true));
expect(document.activeElement).toBe(n);
});
test("false", () => {
const n = r(input(false));
expect(document.activeElement).not.toBe(n);
});
import { useResetDOM, useDOMElement, useIVI, useTest, useHTML, useComputedValue } from "ivi-jest";
import { ElementProtoDescriptor } from "../element_proto";
import { Op } from "ivi";
useResetDOM();
const root = useDOMElement();
const ivi = useIVI();
const h = useHTML();
const t = useTest();
const _ = void 0;
const r = (op: Op) => t.render(op, root()).domNode!;
describe("elementProto", () => {
describe("factory", () => {
const proto = useComputedValue(() => h.div());
const factory = useComputedValue(() => ivi.elementProto(proto));
test("flags", () => {
const op = factory();
expect(op.t.f & ~ivi.NodeFlags.ElementProto).toBe(proto.t.f);
});
test("descriptor", () => {
import { useResetDOM, useSpyOn, useDOMElement, useIVI, useSVG, useTest } from "ivi-jest";
useResetDOM();
const root = useDOMElement();
const setAttributeNS = useSpyOn(() => Element.prototype, "setAttributeNS");
const removeAttribute = useSpyOn(() => Element.prototype, "removeAttribute");
const ivi = useIVI();
const s = useSVG();
const t = useTest();
const _ = void 0;
const r = (value?: string | number) => (
t.render(
s.circle(_, value === void 0 ? void 0 : { "text": s.XML_ATTR(value) }),
root(),
).domNode!
);
describe("attribute directive XLINK_ATTR", () => {
describe("mount", () => {
test("empty string", () => {
const n = r("");
expect(n.getAttributeNS(ivi.XML_NAMESPACE, "text")).toBe("");
expect(setAttributeNS.mock.calls.length).toBe(1);
import { useIVI } from "ivi-jest";
const ivi = useIVI();
describe("Box", () => {
test("should contain value", () => {
expect(ivi.box(10)).toEqual({ v: 10 });
});
});
import { useResetDOM, useDOMElement, useIVI, useTest } from "ivi-jest";
import { Op, OpState } from "ivi";
useResetDOM();
const root = useDOMElement();
const ivi = useIVI();
const t = useTest();
const r = (op: Op) => t.render(op, root()).domNode!;
describe("Ref", () => {
test("mount", () => {
const ref = ivi.box(null);
const op = ivi.Ref(ref, null);
r(op);
expect(ref.v!.o).toBe(op);
});
test("unmount", () => {
const ref = ivi.box(null);
r(ivi.Ref(ref, null));
r(null);
expect(ref.v).toBeNull();
import { useIVI } from "ivi-jest";
const ivi = useIVI();
describe("array", () => {
describe("append", () => {
test("append(null, 1)", () => {
expect(ivi.append(null, 1)).toEqual([1]);
});
test("append([0], 1)", () => {
expect(ivi.append([0], 1)).toEqual([0, 1]);
});
test("same instance", () => {
const a = [0];
const b = ivi.append(a, 1);
expect(a).toBe(b);
});