mirror of
https://github.com/tenrok/vue-meta.git
synced 2026-05-26 11:44:05 +03:00
05163a77a8
* feat: add option for prepending (no)script to body * test: use browser getUrl * refactor: use pbody insteadn of pody * test: add prepend/append body generator test * test: add prepend body updater test * chore: remove typo
40 lines
1.3 KiB
JavaScript
40 lines
1.3 KiB
JavaScript
import { buildFixture } from '../utils/build'
|
|
|
|
describe('basic browser with ssr page', () => {
|
|
let html
|
|
|
|
beforeAll(async () => {
|
|
const fixture = await buildFixture('basic')
|
|
html = fixture.html
|
|
})
|
|
|
|
test('validate ssr', () => {
|
|
const htmlTag = html.match(/<html([^>]+)>/)[0]
|
|
expect(htmlTag).toContain('data-vue-meta-server-rendered ')
|
|
expect(htmlTag).toContain(' lang="en" ')
|
|
expect(htmlTag).toContain(' amp ')
|
|
expect(htmlTag).not.toContain('allowfullscreen')
|
|
expect(html.match(/<title[^>]*>(.*?)<\/title>/)[1]).toBe('Home | Vue Meta Test')
|
|
expect(html.match(/<meta/g).length).toBe(2)
|
|
expect(html.match(/<meta/g).length).toBe(2)
|
|
|
|
// body prepend
|
|
expect(html.match(/<body[^>]*>\s*<noscript/g).length).toBe(1)
|
|
// body append
|
|
expect(html.match(/noscript>\s*<\/body/g).length).toBe(1)
|
|
|
|
const re = /<(no)?script[^>]+type="application\/ld\+json"[^>]*>(.*?)</g
|
|
const sanitizeCheck = []
|
|
let match
|
|
while ((match = re.exec(html))) {
|
|
sanitizeCheck.push(match[2])
|
|
}
|
|
|
|
expect(sanitizeCheck.length).toBe(4)
|
|
expect(() => JSON.parse(sanitizeCheck[0])).not.toThrow()
|
|
expect(() => JSON.parse(sanitizeCheck[1])).toThrow()
|
|
expect(() => JSON.parse(sanitizeCheck[2])).not.toThrow()
|
|
expect(() => JSON.parse(sanitizeCheck[3])).not.toThrow()
|
|
})
|
|
})
|