40 lines
891 B
TypeScript
40 lines
891 B
TypeScript
import { cloneInstance } from "@/lib/utils";
|
|
|
|
describe("cloneInstance", () => {
|
|
class TestClass {
|
|
a: number;
|
|
b: number;
|
|
c: number;
|
|
|
|
constructor(a: number, b: number, c: number) {
|
|
this.a = a;
|
|
this.b = b;
|
|
this.c = c;
|
|
}
|
|
|
|
equals(other: TestClass) {
|
|
return this.a === other.a && this.b === other.b && this.c === other.c;
|
|
}
|
|
|
|
toString() {
|
|
return `TestClass(${this.a}, ${this.b}, ${this.c})`;
|
|
}
|
|
}
|
|
|
|
test("Clones an object", () => {
|
|
const obj = { a: 1, b: 2, c: 3 };
|
|
const clone = cloneInstance(obj);
|
|
expect(clone).toEqual(obj);
|
|
expect(clone).not.toBe(obj);
|
|
});
|
|
|
|
test("Clones an instance of a class", () => {
|
|
const obj = new TestClass(1, 2, 3);
|
|
const clone = cloneInstance(obj);
|
|
expect(clone.equals(obj)).toBe(true);
|
|
expect(clone).not.toBe(obj);
|
|
expect(clone).toBeInstanceOf(TestClass);
|
|
expect(clone.toString()).toBe(obj.toString());
|
|
});
|
|
});
|