Skip to content

Commit 09e8e80

Browse files
authored
chore(schema-org): afterResolve unit test
1 parent d2035a4 commit 09e8e80

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

packages/schema-org/test/ssr/dupes.test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,53 @@ describe('schema.org dupes', () => {
5555
`)
5656
})
5757

58+
it('handles tags without props in afterResolve without crashing', async () => {
59+
const ssrHead = createHead()
60+
61+
ssrHead.use(UnheadSchemaOrg())
62+
63+
ssrHead.hooks.hook('tags:resolve', (ctx) => {
64+
// @ts-expect-error simulating a malformed tag with no props
65+
ctx.tags.push({ tag: 'meta', props: undefined, _p: 0, _w: 0 })
66+
})
67+
ssrHead.hooks.hook('tags:afterResolve', (ctx) => {
68+
ctx.tags = ctx.tags.filter(({ props }) => props !== undefined)
69+
})
70+
71+
useHead(ssrHead, {
72+
script: [
73+
{
74+
type: 'application/ld+json',
75+
key: 'schema-org-graph',
76+
// @ts-expect-error untyped
77+
nodes: [
78+
defineWebSite({
79+
url: '/',
80+
inLanguage: 'en',
81+
name: 'hello',
82+
}),
83+
],
84+
},
85+
],
86+
})
87+
88+
const data = await renderSSRHead(ssrHead)
89+
expect(data.bodyTags).toMatchInlineSnapshot(`
90+
"<script type="application/ld+json" data-hid="schema-org-graph">{
91+
"@context": "https://schema.org",
92+
"@graph": [
93+
{
94+
"@id": "#website",
95+
"@type": "WebSite",
96+
"inLanguage": "en",
97+
"name": "hello",
98+
"url": "/"
99+
}
100+
]
101+
}</script>"
102+
`)
103+
})
104+
58105
it('handles three or more duplicate schema-org entries without crashing', async () => {
59106
const ssrHead = createHead()
60107

0 commit comments

Comments
 (0)