/
index.test.tsx
63 lines (51 loc) · 1.74 KB
/
index.test.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import * as React from "react";
import serializer from ".";
describe("Serializer test function", () => {
// This is how React Helmet sets data of the element. An end user likely wouldn't do this on their own.
it("returns true when given a JSON+LD script element with data set dangerously", () => {
const element = (
<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify({}) }}
/>
);
const shouldSerialize = serializer.test(element);
expect(shouldSerialize).toEqual(true);
});
it("returns false when given a script element that's not JSON+LD", () => {
const element = (
<script
type="application/json"
dangerouslySetInnerHTML={{ __html: JSON.stringify({}) }}
/>
);
const shouldSerialize = serializer.test(element);
expect(shouldSerialize).toEqual(false);
});
it("returns false when given a non-script element", () => {
const element = <div />;
const shouldSerialize = serializer.test(element);
expect(shouldSerialize).toEqual(false);
});
it("returns false if value is undefined", () => {
const shouldSerialize = serializer.test(undefined);
expect(shouldSerialize).toEqual(false);
});
});
describe("Serialization function", () => {
it("serializes a JSON+LD script element with data set dangerously correctly", () => {
expect.addSnapshotSerializer(serializer);
const ldScriptElement = (
<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify({}) }}
/>
);
expect(ldScriptElement).toMatchSnapshot();
});
});
describe("Serialization module", () => {
it("matches expectations", () => {
expect(serializer).toMatchSnapshot();
});
});