Skip to content

Commit 0eed83c

Browse files
committed
refactor: extract boolean statement into seperate functions
1 parent 9d0e903 commit 0eed83c

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/index.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
2+
13
import * as React from "react";
24

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+
13+
function hasValidProps(val: any): boolean {
14+
return Boolean(
15+
val.props &&
16+
val.props.dangerouslySetInnerHTML &&
17+
val.props.type &&
18+
val.props.type === "application/ld+json"
19+
);
20+
}
21+
322
const JSONLDSerializer: jest.SnapshotSerializerPlugin = {
423
test(val) {
524
return Boolean(
6-
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"
25+
val && isReactElement(val) && isScriptElement(val) && hasValidProps(val)
1226
);
1327
},
1428

0 commit comments

Comments
 (0)