From 682ecdfa12840120f617ea12d6f5133ea7932413 Mon Sep 17 00:00:00 2001 From: Greegko Date: Tue, 8 Nov 2022 11:28:04 +0100 Subject: [PATCH] add expected states array --- packages/core-test/tests/utils/test.ts | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/core-test/tests/utils/test.ts b/packages/core-test/tests/utils/test.ts index 81a293a..673aaa4 100644 --- a/packages/core-test/tests/utils/test.ts +++ b/packages/core-test/tests/utils/test.ts @@ -19,7 +19,7 @@ type Test = { config?: GameConfig["config"]; commands?: (Command | string)[]; turn?: boolean | number; - expectedState: ExpectedState; + expectedState: ExpectedState | ExpectedState[]; }; export function test(testName: string, { config, initState, commands, expectedState, turn = 0 }: Test) { @@ -42,14 +42,22 @@ export function test(testName: string, { config, initState, commands, expectedSt const gameState = game.getState(); - if (typeof expectedState === "object") { - t.like(gameState, expectedState); + const testExpectedState = (expectedState: ExpectedState) => { + if (typeof expectedState === "object") { + t.like(gameState, expectedState); + } else { + expectedState(gameState, { + ...t, + withRandomId: withRandomIDAssertionFactory(t), + length: lengthAssertionFactory(t), + }); + } + } + + if(Array.isArray(expectedState)) { + expectedState.forEach(testExpectedState); } else { - expectedState(gameState, { - ...t, - withRandomId: withRandomIDAssertionFactory(t), - length: lengthAssertionFactory(t), - }); + testExpectedState(expectedState); } }); }