From d91eda8556f8148c12505a662fab0d4bf39e4b97 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Sat, 28 May 2016 08:17:57 +0900 Subject: [PATCH] add options el tests (#2967) * add options el tests ref: #2872 * fix error at phantomjs env --- test/unit/features/options/el.spec.js | 65 +++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/test/unit/features/options/el.spec.js b/test/unit/features/options/el.spec.js index e69de29b..973e7dcc 100644 --- a/test/unit/features/options/el.spec.js +++ b/test/unit/features/options/el.spec.js @@ -0,0 +1,65 @@ +import Vue from 'vue' + +describe('Options el', () => { + it('basic usage', () => { + const el = document.createElement('div') + el.innerHTML = '{{message}}' + const vm = new Vue({ + el, + data: { message: 'hello world' } + }) + expect(vm.$el.tagName).toBe('DIV') + expect(vm.$el.textContent).toBe(vm.message) + }) + + it('should be replaced when use togther with `template` option', () => { + const el = document.createElement('div') + el.innerHTML = '{{message}}' + const vm = new Vue({ + el, + template: '

{{message}}

', + data: { message: 'hello world' } + }) + expect(vm.$el.tagName).toBe('P') + expect(vm.$el.textContent).toBe(vm.message) + }) + + it('should be replaced when use togther with `render` option', () => { + const el = document.createElement('div') + el.innerHTML = '{{message}}' + const vm = new Vue({ + el, + render () { + const h = this.$createElement + return h('p', { staticAttrs: { id: 'app' }}, [ + h('span', {}, [this.message]) + ]) + }, + data: { message: 'hello world' } + }) + expect(vm.$el.tagName).toBe('P') + expect(vm.$el.textContent).toBe(vm.message) + }) + + it('svg element', () => { + const ns = 'http://www.w3.org/2000/svg' + const el = document.createElementNS(ns, 'svg') + const text = document.createElementNS(ns, 'text') + text.setAttribute(':x', 'x') + text.setAttribute(':y', 'y') + text.setAttribute(':fill', 'color') + text.textContent = '{{text}}' + el.appendChild(text) + const vm = new Vue({ + el, + data: { + x: 64, y: 128, color: 'red', text: 'svg text' + } + }) + expect(vm.$el.tagName).toBe('svg') + expect(vm.$el.childNodes[0].getAttribute('x')).toBe(vm.x.toString()) + expect(vm.$el.childNodes[0].getAttribute('y')).toBe(vm.y.toString()) + expect(vm.$el.childNodes[0].getAttribute('fill')).toBe(vm.color) + expect(vm.$el.childNodes[0].textContent).toBe(vm.text) + }) +})