Skip to content
This repository was archived by the owner on Dec 30, 2023. It is now read-only.

Commit e42bcff

Browse files
committed
refactor(test/unit): ♻️ Print items/entries size/length of the iterable values
1 parent 1837e4f commit e42bcff

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

packages/test/source/unit/unit.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,15 @@ function getFormattedNonPrimitiveValue(value: unknown, valueType: string): strin
8181
switch (valueType) {
8282
/* eslint-disable unicorn/switch-case-braces */
8383
case "Array":
84+
return `[ ...${(value as Array<unknown>).length} item(s)... ]`;
8485
case "Set":
85-
return getStringifiedAndTruncatedArray([...(value as Array<unknown> | Set<unknown>)]);
86+
return `[ ...${(value as Set<unknown>).size} item(s)... ]`;
8687
case "Error":
8788
return (value as Error).message;
89+
case "Map":
90+
return `{ ...${(value as Map<unknown, unknown>).size} entry(ies)... }`;
91+
case "Object":
92+
return `{ ...${Object.entries(value as object).length} entry(ies)... }`;
8893
default:
8994
return "";
9095
/* eslint-enable unicorn/switch-case-braces */
@@ -97,18 +102,6 @@ function stringifyValue(value: unknown, valueType: string): string | undefined {
97102
: getFormattedNonPrimitiveValue(value, valueType);
98103
}
99104

100-
function jsonReplacer(_key: string, value: unknown) {
101-
/* prettier-ignore */
102-
switch(typeof value) {
103-
/* eslint-disable unicorn/switch-case-braces */
104-
case "bigint": return `${value.toString()}n`;
105-
case "function": return value.toString();
106-
case "undefined": return `undefined`;
107-
default: return value;
108-
/* eslint-enable unicorn/switch-case-braces */
109-
}
110-
}
111-
112105
function getStringifiedAndTruncatedArray(array: Array<unknown>): string {
113106
const { length } = array;
114107
const maxLength = 4;
@@ -156,5 +149,17 @@ function createPrint(prefixEmoji: string, prefix: string, value: unknown | Custo
156149
return `${prefixEmoji} ${prefix} ${valueTypeEmoji} '${valueTypeName}'${displayStringifiedValue}`;
157150
}
158151

152+
function jsonReplacer(_key: string, value: unknown) {
153+
/* prettier-ignore */
154+
switch(typeof value) {
155+
/* eslint-disable unicorn/switch-case-braces */
156+
case "bigint": return `${value.toString()}n`;
157+
case "function": return value.toString();
158+
case "undefined": return `undefined`;
159+
default: return value;
160+
/* eslint-enable unicorn/switch-case-braces */
161+
}
162+
}
163+
159164
export const throws = (value: unknown) => createPrint(`💥`, `throws`, value);
160165
export const returns = (value?: unknown) => createPrint(`🔙`, `returns`, value);

0 commit comments

Comments
 (0)