Skip to content

Commit 4fb981d

Browse files
committed
fix: test function returns false if value is undefined
1 parent d5886c4 commit 4fb981d

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/index.test.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ describe("Serializer test function", () => {
3333

3434
expect(shouldSerialize).toEqual(false);
3535
});
36+
37+
it("returns false if value is undefined", () => {
38+
const shouldSerialize = serializer.test(undefined);
39+
40+
expect(shouldSerialize).toEqual(false);
41+
});
3642
});
3743

3844
describe("Serialization function", () => {

src/index.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import * as React from "react";
22

33
const JSONLDSerializer: jest.SnapshotSerializerPlugin = {
44
test(val) {
5-
return (
5+
return Boolean(
66
val &&
7-
val.$$typeof === Symbol.for("react.element") &&
8-
val.type === "script" &&
9-
val.props.dangerouslySetInnerHTML &&
10-
val.props.type &&
11-
val.props.type === "application/ld+json"
7+
val.$$typeof === Symbol.for("react.element") &&
8+
val.type === "script" &&
9+
val.props.dangerouslySetInnerHTML &&
10+
val.props.type &&
11+
val.props.type === "application/ld+json"
1212
);
1313
},
1414

0 commit comments

Comments
 (0)