Skip to content

Commit

Permalink
refactor: use React utility function and simplify boolean expresions
Browse files Browse the repository at this point in the history
  • Loading branch information
keplersj committed Aug 20, 2019
1 parent 86266e4 commit f098922
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,9 @@

import * as React from "react";

function isReactElement(val: any): boolean {
return Boolean(val.$$typeof && val.$$typeof === Symbol.for("react.element"));
}

function isScriptElement(val: any): boolean {
return Boolean(val.type && val.type === "script");
}

function hasValidProps(val: any): boolean {
return Boolean(
val.props &&
val.props.dangerouslySetInnerHTML &&
val.props.dangerouslySetInnerHTML &&
val.props.type &&
val.props.type === "application/ld+json"
);
Expand All @@ -22,7 +13,10 @@ function hasValidProps(val: any): boolean {
const JSONLDSerializer: jest.SnapshotSerializerPlugin = {
test(val) {
return Boolean(
val && isReactElement(val) && isScriptElement(val) && hasValidProps(val)
val &&
React.isValidElement(val) &&
val.type === "script" &&
hasValidProps(val)
);
},

Expand Down

0 comments on commit f098922

Please sign in to comment.