Something went wrong. Try again.
Starship Simulator Controls thoriumsim.com
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061import { describe, expect, it } from "vitest";
import Entity from "../entity";
describe("Entity", () => { it("should initialize", () => { const entity = new Entity();
expect(typeof entity.id).toBe("number"); });
it("should have an unique id", () => { const entity1 = new Entity(); const entity2 = new Entity();
expect(entity1.id !== entity2.id).toBeTruthy(); });
it("should support getDefault components", () => { const entity = new Entity(0, { identity: { name: "bar" } });
expect(entity.components.identity?.name).toEqual("bar"); });
it("should support default data", () => { const entity = new Entity(null, { identity: { name: "Testing!", description: "This is a test.", }, }); expect(entity.components.identity).toEqual({ name: "Testing!", description: "This is a test.", }); });
describe("addComponent()", () => { it("should add a default object when a component name is passed", () => { const entity = new Entity(); expect(entity.components.identity).toEqual(undefined); entity.addComponent("identity"); expect(entity.components.identity?.name).toEqual("Entity"); expect(entity.components.identity?.description).toBeUndefined(); }); });
describe("updateComponent()", () => { it("should update an existing component", () => { const entity = new Entity(); entity.addComponent("identity", { name: "bar" });
expect(entity.components.identity?.name).toEqual("bar");
entity.updateComponent("identity", { name: "foo" });
expect(entity.components.identity?.name).toEqual("foo"); }); });});