From 26e1bdf056ae3227117f7da1fd90b8cca9a68f04 Mon Sep 17 00:00:00 2001 From: Sergio Cabral Date: Sun, 8 Aug 2021 17:27:10 -0300 Subject: [PATCH] Unit test for: Automatically delete memory of missing creeps (#158) --- test/unit/main.test.ts | 12 ++++++++++++ test/unit/mock.ts | 15 +++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/test/unit/main.test.ts b/test/unit/main.test.ts index 614c830..9aef876 100644 --- a/test/unit/main.test.ts +++ b/test/unit/main.test.ts @@ -22,4 +22,16 @@ describe("main", () => { it("should return void when called with no context", () => { assert.isUndefined(loop()); }); + + it("Automatically delete memory of missing creeps", () => { + Memory.creeps.persistValue = "any value"; + Memory.creeps.notPersistValue = "any value"; + + Game.creeps.persistValue = "any value"; + + loop(); + + assert.isDefined(Memory.creeps.persistValue); + assert.isUndefined(Memory.creeps.notPersistValue); + }); }); diff --git a/test/unit/mock.ts b/test/unit/mock.ts index a7a868f..add6585 100644 --- a/test/unit/mock.ts +++ b/test/unit/mock.ts @@ -1,10 +1,17 @@ -export const Game = { - creeps: [], +export const Game: { + creeps: { [name: string]: any }; + rooms: any; + spawns: any; + time: any; +} = { + creeps: {}, rooms: [], spawns: {}, time: 12345 }; -export const Memory = { - creeps: [] +export const Memory: { + creeps: { [name: string]: any }; +} = { + creeps: {} };