Skip to content

Commit 7380db7

Browse files
committed
chore(nuxt): add tests for plugin hook
1 parent 8bca3ea commit 7380db7

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<template>
2+
<div>
3+
<h1>Plugin Override</h1>
4+
</div>
5+
</template>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { defineNuxtPlugin } from '#app'
2+
3+
export default defineNuxtPlugin((nuxtApp) => {
4+
nuxtApp.hooks.hook('schema-org:meta', (meta) => {
5+
if (nuxtApp._route.path === '/plugin-override') {
6+
meta.host = 'https://override-example.com'
7+
meta.url = `${meta.host}${meta.path}`
8+
}
9+
})
10+
})

test/nuxt/basic.test.ts

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,59 @@ describe('pages', () => {
112112
expect(webpageNode.url).toEqual('https://example.com/title-override')
113113
expect(webpageNode.name).toEqual('Title Override')
114114

115-
await expectNoClientErrors('/')
115+
await expectNoClientErrors('/title-override')
116+
})
117+
118+
it('render plugin override', async () => {
119+
const schema = await $fetchSchemaOrg('/plugin-override')
120+
121+
// Snapshot
122+
expect(schema).toMatchInlineSnapshot(`
123+
{
124+
"@context": "https://schema.org",
125+
"@graph": [
126+
{
127+
"@id": "https://override-example.com/#identity",
128+
"@type": "Person",
129+
"jobTitle": "Software Engineer",
130+
"name": "Harlan",
131+
"url": "https://override-example.com",
132+
},
133+
{
134+
"@id": "https://override-example.com/#website",
135+
"@type": "WebSite",
136+
"name": "My Website",
137+
"publisher": {
138+
"@id": "https://override-example.com/#identity",
139+
},
140+
"url": "https://override-example.com",
141+
},
142+
{
143+
"@id": "https://override-example.com/plugin-override/#webpage",
144+
"@type": "WebPage",
145+
"about": {
146+
"@id": "https://override-example.com/#identity",
147+
},
148+
"isPartOf": {
149+
"@id": "https://override-example.com/#website",
150+
},
151+
"potentialAction": [
152+
{
153+
"@type": "ReadAction",
154+
"target": [
155+
"https://override-example.com/plugin-override",
156+
],
157+
},
158+
],
159+
"url": "https://override-example.com/plugin-override",
160+
},
161+
],
162+
}
163+
`)
164+
165+
const webpageNode = schema['@graph'].filter(n => n['@type'] === 'WebPage')[0]
166+
expect(webpageNode.url).toEqual('https://override-example.com/plugin-override')
167+
168+
await expectNoClientErrors('/plugin-override')
116169
})
117170
})

0 commit comments

Comments
 (0)