diff --git a/README.md b/README.md
index 927cbf7..9099d7c 100644
--- a/README.md
+++ b/README.md
@@ -50,6 +50,39 @@ export function GraceHopper() {
}
```
+### Directly creating `',
- })).toMatchInlineSnapshot(`
+test("escapes JSON-LD-illegal chars", () => {
+ expect(
+ helmetJsonLdProp({
+ "@context": "https://schema.org",
+ "@type": "Person",
+ name: "Foo",
+ })
+ ).toMatchInlineSnapshot(`
Object {
"innerHTML": "{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Person\\",\\"name\\":\\"Foo</script>\\"}",
"type": "application/ld+json",
}
`);
+
+ expect(
+ jsonLdScriptProps({
+ "@context": "https://schema.org",
+ "@type": "Person",
+ name: "Foo",
+ })
+ ).toMatchInlineSnapshot(`
+ Object {
+ "dangerouslySetInnerHTML": Object {
+ "__html": "{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Person\\",\\"name\\":\\"Foo</script>\\"}",
+ },
+ "type": "application/ld+json",
+ }
+ `);
});
-test('escapes JSON-LD-illegal chars', () => {
- expect(helmetJsonLdProp(
- {
- '@context': 'https://schema.org',
- '@type': 'Person',
- name: ['Foo', null!, undefined!],
- knows: [],
- knowsAbout: {
- '@type': 'CreativeWork',
- name: 'Foo',
- copyrightYear: 2020,
- },
- },
- {space: 2}))
- .toMatchInlineSnapshot(`
+test("escapes JSON-LD-illegal chars", () => {
+ expect(
+ helmetJsonLdProp(
+ {
+ "@context": "https://schema.org",
+ "@type": "Person",
+ name: ["Foo", null!, undefined!],
+ knows: [],
+ knowsAbout: {
+ "@type": "CreativeWork",
+ name: "Foo",
+ copyrightYear: 2020,
+ },
+ },
+ { space: 2 }
+ )
+ ).toMatchInlineSnapshot(`
Object {
"innerHTML": "{
\\"@context\\": \\"https://schema.org\\",
@@ -61,4 +133,42 @@ test('escapes JSON-LD-illegal chars', () => {
"type": "application/ld+json",
}
`);
+
+ expect(
+ jsonLdScriptProps(
+ {
+ "@context": "https://schema.org",
+ "@type": "Person",
+ name: ["Foo", null!, undefined!],
+ knows: [],
+ knowsAbout: {
+ "@type": "CreativeWork",
+ name: "Foo",
+ copyrightYear: 2020,
+ },
+ },
+ { space: 2 }
+ )
+ ).toMatchInlineSnapshot(`
+ Object {
+ "dangerouslySetInnerHTML": Object {
+ "__html": "{
+ \\"@context\\": \\"https://schema.org\\",
+ \\"@type\\": \\"Person\\",
+ \\"name\\": [
+ \\"Foo</script>\\",
+ null,
+ null
+ ],
+ \\"knows\\": [],
+ \\"knowsAbout\\": {
+ \\"@type\\": \\"CreativeWork\\",
+ \\"name\\": \\"Foo\\",
+ \\"copyrightYear\\": 2020
+ }
+ }",
+ },
+ "type": "application/ld+json",
+ }
+ `);
});