How to use ivi-jest - 10 common examples

To help you get started, we’ve selected a few ivi-jest examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github localvoid / ivi / packages / ivi / src / core / __tests__ / function.spec.ts View on Github external
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";
github localvoid / ivi / packages / ivi / src / events / __tests__ / event_handlers.spec.ts View on Github external
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);
  });
github localvoid / ivi / packages / ivi / src / vdom / __tests__ / element.spec.ts View on Github external
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();
      });
    });
  });
});
github localvoid / ivi / packages / ivi / src / core / __tests__ / repeatable_task_list.spec.ts View on Github external
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", () => {
github localvoid / ivi / packages / ivi / src / vdom / __tests__ / attribute_directive_autofocus.spec.ts View on Github external
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);
    });
github localvoid / ivi / packages / ivi / src / vdom / __tests__ / elementProto.spec.ts View on Github external
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", () => {
github localvoid / ivi / packages / ivi / src / vdom / __tests__ / attribute_directive_xml.spec.ts View on Github external
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);
github localvoid / ivi / packages / ivi / src / core / __tests__ / box.spec.ts View on Github external
import { useIVI } from "ivi-jest";

const ivi = useIVI();

describe("Box", () => {
  test("should contain value", () => {
    expect(ivi.box(10)).toEqual({ v: 10 });
  });
});
github localvoid / ivi / packages / ivi / src / vdom / __tests__ / ref.spec.ts View on Github external
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();
github localvoid / ivi / packages / ivi / src / core / __tests__ / array.spec.ts View on Github external
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);
    });

ivi-jest

Jest utils for ivi library

MIT
Latest version published 6 years ago

Package Health Score

52 / 100
Full package analysis

Popular ivi-jest functions