-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: Thomas Lamant <tom@tmlmt.com>
- Loading branch information
Showing
4 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { describe, expect, it } from 'vitest' | ||
import { createHead, useHead } from 'unhead' | ||
import { defineWebPage, useSchemaOrg } from '@unhead/schema-org' | ||
|
||
describe('schema.org ssr ids', () => { | ||
it('adds host prefix to custom id without host', async () => { | ||
const ssrHead = createHead() | ||
|
||
useHead({ | ||
templateParams: { | ||
schemaOrg: { | ||
host: 'https://example.com', | ||
}, | ||
}, | ||
}) | ||
|
||
useSchemaOrg([ | ||
defineWebPage({ | ||
'@id': '#foo', | ||
'name': 'foo', | ||
}), | ||
]) | ||
|
||
|
||
const tags = await ssrHead.resolveTags() | ||
const id = JSON.parse(tags[0].innerHTML!)['@graph'][0]['@id'] | ||
expect(id).toMatchInlineSnapshot('"https://example.com/#foo"') | ||
}) | ||
it('allows ids with custom domains', async () => { | ||
const ssrHead = createHead() | ||
|
||
useHead({ | ||
templateParams: { | ||
schemaOrg: { | ||
host: 'https://example.com', | ||
}, | ||
}, | ||
}) | ||
|
||
useSchemaOrg([ | ||
defineWebPage({ | ||
'@id': 'https://custom-domain.com/#foo', | ||
'name': 'foo', | ||
}), | ||
]) | ||
|
||
const tags = await ssrHead.resolveTags() | ||
const id = JSON.parse(tags[0].innerHTML!)['@graph'][0]['@id'] | ||
expect(id).toMatchInlineSnapshot('"https://custom-domain.com/#foo"') | ||
}) | ||
}) |