rc-js-util
Version:
A collection of TS and C++ utilities to help writing performant and correct applications, achieved through strict typing and (removable) invariant checking.
35 lines (30 loc) • 1.14 kB
text/typescript
import { arrayIntersect } from "./array-intersect.js";
import { Test_setDefaultFlags } from "../../test-util/test_set-default-flags.js";
describe("=> arrayIntersect", () =>
{
beforeEach(() =>
{
Test_setDefaultFlags();
});
const a = ["a", "b", "c"] as const;
const b = ["a", "d", "e"] as const;
it("| calls the callback with the correct parameters", () =>
{
const spy = jasmine.createSpy();
spy.and.returnValue(null);
arrayIntersect(a, b, spy);
expect(spy.calls.count()).toBe(6);
// call order not important, only arguments
expect(spy.calls.argsFor(0)).toEqual(["a", 0]);
expect(spy.calls.argsFor(1)).toEqual(["d", 1]);
expect(spy.calls.argsFor(2)).toEqual(["e", 2]);
expect(spy.calls.argsFor(3)).toEqual(["a", 0]);
expect(spy.calls.argsFor(4)).toEqual(["b", 1]);
expect(spy.calls.argsFor(5)).toEqual(["c", 2]);
});
it("| returns the intersection", () =>
{
const result: ("a" | "b" | "c" | "d" | "e")[] = arrayIntersect(a, b, (value) => value);
expect(result).toEqual(["a"]);
});
});