Skip to content

Commit 2872b8d

Browse files
committed
Merge branch 'master' of github.com:mattapperson/slapshot
2 parents 78bdc3a + ea4782d commit 2872b8d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/memorize.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,18 @@ test("works with undefined value", async () => {
170170
expect(data).toBeUndefined();
171171
});
172172

173+
test("works with array value", async () => {
174+
process.argv.push("--updateSnapshot");
175+
process.env.SLAPSHOT_ONLINE = "true";
176+
177+
memorize("c", () => [1, 2, 3]);
178+
179+
process.argv = process.argv.filter(e => e !== "--updateSnapshot");
180+
process.env.SLAPSHOT_ONLINE = "false";
181+
const data = memorize("c", () => {});
182+
expect(data).toEqual([1, 2, 3]);
183+
});
184+
173185
test("nested APIs with functions throw an error when called unless mocked manualy", async () => {
174186
process.argv.push("--updateSnapshot");
175187
process.env.SLAPSHOT_ONLINE = "true";

src/safeSnapshot.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
export function safeSnapshot(obj: any, toSnapshot: boolean = true) {
1+
export function safeSnapshot(obj: any, toSnapshot: boolean = true): any {
22
if (typeof obj !== "object") {
33
return obj;
44
}
55
if (obj === null) {
66
return null;
77
}
8+
9+
if (Array.isArray(obj)) {
10+
return obj.map((val: any) => safeSnapshot(val, toSnapshot));
11+
}
12+
813
return Object.keys(obj).reduce(
914
(safeObject, key) => {
1015
if (

0 commit comments

Comments
 (0)