Files
project-inter-server/test/types/TupleKeyTests.test.ts

31 lines
964 B
TypeScript

import { describe, expect, it } from "@jest/globals";
import { TupleKey } from "../../src/types/TupleKey";
describe("TupleKey", () => {
it("stores a value copy of the original tuple", () => {
const tuple: [string, string] = ["150", "539"];
const tupleKey = new TupleKey(...tuple);
expect(tupleKey.tuple).toEqual(tuple);
});
it("returns a string representation of itself", () => {
const tuple: [string, string] = ["150", "539"];
const tupleKey = new TupleKey(...tuple);
expect(`${tupleKey}`).toEqual("150|539");
});
it("supports usage as key in object", () => {
const tupleKey1 = new TupleKey("1", "2");
const tupleKey2 = new TupleKey("3", "4");
const sampleObject = {
[tupleKey1.toString()]: "value1",
[tupleKey2.toString()]: "value2",
};
expect(sampleObject[tupleKey1.toString()]).toEqual("value1");
expect(sampleObject[(new TupleKey("1", "2")).toString()]).toEqual("value1");
});
});