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

46 lines
1.4 KiB
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");
});
describe("fromExistingStringKey", () => {
it("creates a new TupleKey from an existing string key", () => {
const strKey = "hello|there";
const tupleKey = TupleKey.fromExistingStringKey(strKey);
expect(tupleKey.toString()).toEqual(strKey);
});
it("creates an empty tuple if there is no string", () => {
const strKey = "";
const tupleKey = TupleKey.fromExistingStringKey(strKey);
expect(tupleKey.toString()).toEqual(strKey);
})
})
});