import Vue from 'vue'
describe('Delimiters', () => {
it('default delimiters should work', () => {
const vm = new Vue({
data: {
a: 1
},
template: '
{{ a }}
'
}).$mount()
expect(vm.$el.textContent).toEqual('1')
})
it('custom delimiters should work', () => {
const vm = new Vue({
delimiters: ['[[', ']]'],
template: '[[ a ]]
',
data: {
a: 1
}
}).$mount()
expect(vm.$el.textContent).toEqual('1')
})
it('default delimiters should be ignored when custom delimiters defined', () => {
const vm = new Vue({
delimiters: ['[[', ']]'],
template: '{{ a }}
',
data: {
a: 1
}
}).$mount()
expect(vm.$el.textContent).toEqual('{{ a }}')
})
it('delimiters should only affect vm', () => {
const Component = Vue.extend({
data: function () {
return {
b: 2
}
},
template: '[[ b ]]'
})
const vm = new Vue({
delimiters: ['[[', ']]'],
template: '[[ a ]] -
',
data: {
a: 2
},
components: {
'test-component': Component
}
}).$mount()
expect(vm.$el.textContent).toEqual('2 - [[ b ]]')
})
it('delimiters defined globally should work on all vms', () => {
Vue.options.delimiters = ['[[', ']]']
const Component = Vue.extend({
template: '[[ a ]]',
data: function () {
return {
a: 2
}
}
})
const vm = new Vue({
data: {
b: 1
},
template: '[[ b ]] -
',
components: {
'test-component': Component
}
}).$mount()
expect(vm.$el.textContent).toEqual('1 - 2')
// restore default options
delete Vue.options.delimiters
})
it('component specific delimiters should override global delimiters', () => {
Vue.options.delimiters = ['[[', ']]']
const Component = Vue.extend({
delimiters: ['@{{', '}}'],
template: '@{{ a }}',
data: function () {
return {
a: 2
}
}
})
const vm = new Vue({
data: {
b: 1
},
template: '[[ b ]] -
',
components: {
'test-component': Component
}
}).$mount()
expect(vm.$el.textContent).toEqual('1 - 2')
// restore default options
delete Vue.options.delimiters
})
})