2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-06-06 07:32:24 +03:00
Files

44 lines
1.4 KiB
JavaScript

import { buildFixture } from '../utils/build'
describe('basic browser with ssr page', () => {
let html
test('build', async () => {
const fixture = await buildFixture('basic')
expect(fixture).toBeDefined()
expect(fixture.html).toBeDefined()
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()
})
})