2
0
mirror of https://github.com/tenrok/vue-meta.git synced 2026-05-17 16:59:38 +03:00
Files
vue-meta/test/unit/escaping.test.js
T

75 lines
2.0 KiB
JavaScript

import _getMetaInfo from '../../src/shared/getMetaInfo'
import { loadVueMetaPlugin } from '../utils'
import { defaultOptions } from '../../src/shared/constants'
const getMetaInfo = (component, escapeSequences) => _getMetaInfo(defaultOptions, component, escapeSequences)
describe('escaping', () => {
let Vue
beforeAll(() => (Vue = loadVueMetaPlugin()))
test('special chars are escaped unless disabled', () => {
const component = new Vue({
metaInfo: {
htmlAttrs: { key: 1 },
title: 'Hello & Goodbye',
script: [{ innerHTML: 'Hello & Goodbye' }],
__dangerouslyDisableSanitizers: ['script']
}
})
expect(getMetaInfo(component, [[/&/g, '&']])).toEqual({
title: 'Hello & Goodbye',
titleChunk: 'Hello & Goodbye',
titleTemplate: '%s',
htmlAttrs: {
key: 1
},
headAttrs: {},
bodyAttrs: {},
meta: [],
base: [],
link: [],
style: [],
script: [{ innerHTML: 'Hello & Goodbye' }],
noscript: [],
__dangerouslyDisableSanitizers: ['script'],
__dangerouslyDisableSanitizersByTagID: {}
})
})
test('special chars are escaped unless disabled by vmid', () => {
const component = new Vue({
metaInfo: {
title: 'Hello',
script: [
{ vmid: 'yescape', innerHTML: 'Hello & Goodbye' },
{ vmid: 'noscape', innerHTML: 'Hello & Goodbye' }
],
__dangerouslyDisableSanitizersByTagID: { noscape: ['innerHTML'] }
}
})
expect(getMetaInfo(component, [[/&/g, '&']])).toEqual({
title: 'Hello',
titleChunk: 'Hello',
titleTemplate: '%s',
htmlAttrs: {},
headAttrs: {},
bodyAttrs: {},
meta: [],
base: [],
link: [],
style: [],
script: [
{ innerHTML: 'Hello & Goodbye', vmid: 'yescape' },
{ innerHTML: 'Hello & Goodbye', vmid: 'noscape' }
],
noscript: [],
__dangerouslyDisableSanitizers: [],
__dangerouslyDisableSanitizersByTagID: { noscape: ['innerHTML'] }
})
})
})