diff --git a/src/index.test.tsx b/src/index.test.tsx index 50ee89f..008f17d 100644 --- a/src/index.test.tsx +++ b/src/index.test.tsx @@ -33,6 +33,12 @@ describe("Serializer test function", () => { expect(shouldSerialize).toEqual(false); }); + + it("returns false if value is undefined", () => { + const shouldSerialize = serializer.test(undefined); + + expect(shouldSerialize).toEqual(false); + }); }); describe("Serialization function", () => { diff --git a/src/index.tsx b/src/index.tsx index 9b18c4e..a75f978 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -2,13 +2,13 @@ import * as React from "react"; const JSONLDSerializer: jest.SnapshotSerializerPlugin = { test(val) { - return ( + return Boolean( val && - val.$$typeof === Symbol.for("react.element") && - val.type === "script" && - val.props.dangerouslySetInnerHTML && - val.props.type && - val.props.type === "application/ld+json" + val.$$typeof === Symbol.for("react.element") && + val.type === "script" && + val.props.dangerouslySetInnerHTML && + val.props.type && + val.props.type === "application/ld+json" ); },