Skip to content

Commit

Permalink
add expected states array
Browse files Browse the repository at this point in the history
  • Loading branch information
Greegko committed Nov 8, 2022
1 parent eece642 commit 682ecdf
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions packages/core-test/tests/utils/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
});
}

0 comments on commit 682ecdf

Please sign in to comment.