Skip to content

Commit f098922

Browse files
committed
refactor: use React utility function and simplify boolean expresions
1 parent 86266e4 commit f098922

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

src/index.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,9 @@
22

33
import * as React from "react";
44

5-
function isReactElement(val: any): boolean {
6-
return Boolean(val.$$typeof && val.$$typeof === Symbol.for("react.element"));
7-
}
8-
9-
function isScriptElement(val: any): boolean {
10-
return Boolean(val.type && val.type === "script");
11-
}
12-
135
function hasValidProps(val: any): boolean {
146
return Boolean(
15-
val.props &&
16-
val.props.dangerouslySetInnerHTML &&
7+
val.props.dangerouslySetInnerHTML &&
178
val.props.type &&
189
val.props.type === "application/ld+json"
1910
);
@@ -22,7 +13,10 @@ function hasValidProps(val: any): boolean {
2213
const JSONLDSerializer: jest.SnapshotSerializerPlugin = {
2314
test(val) {
2415
return Boolean(
25-
val && isReactElement(val) && isScriptElement(val) && hasValidProps(val)
16+
val &&
17+
React.isValidElement(val) &&
18+
val.type === "script" &&
19+
hasValidProps(val)
2620
);
2721
},
2822

0 commit comments

Comments
 (0)