diff --git a/test/e2e/index.js b/test/e2e/index.js index bf362d1e1..cb22c17c8 100644 --- a/test/e2e/index.js +++ b/test/e2e/index.js @@ -1,5 +1,6 @@ import Vue from 'vue' import plugin from '../../src/index' +import compare from '../../src/compare' Vue.use(plugin, { lang: 'en', @@ -21,8 +22,18 @@ Vue.use(plugin, { } }) -const translation = { - template: '

{{* $t("message.hello", "en", { name: "kazupon" })}}
How are you?

' +const translation = {} + +if (compare(Vue.version, '2.0.0-alpha') < 0) { + translation.template = '

{{* $t("message.hello", "en", { name: "kazupon" })}}
How are you?

' +} else { + translation.render = function () { + return this.$createElement('p', { staticAttrs: { id: 'message' } }, [ + this.__toString__(this.$t('message.hello', 'en', { name: 'kazupon' })), + this.$createElement('br'), + 'How are you?' + ]) + } } new Vue(translation).$mount('#translation') diff --git a/test/specs/component.js b/test/specs/component.js index 158cedc68..1cd1c25f2 100644 --- a/test/specs/component.js +++ b/test/specs/component.js @@ -1,6 +1,7 @@ import assert from 'power-assert' import Vue from 'vue' import locales from './fixture/locales' +import compare from '../../src/compare' describe('component locales', () => { @@ -14,9 +15,8 @@ describe('component locales', () => { let vm beforeEach(done => { - vm = new Vue({ + const options = { el: document.createElement('div'), - template: '
', components: { component1: { locales: { @@ -30,7 +30,19 @@ describe('component locales', () => { } } } - }) + } + + if (compare(Vue.version, '2.0.0-alpha') < 0) { + options.template = '
' + } else { + options.render = function () { + return this.$createElement('div', {}, [ + this.$createElement('component1', {}) + ]) + } + } + + vm = new Vue(options) vm.$nextTick(done) }) diff --git a/test/specs/i18n.js b/test/specs/i18n.js index 9c54bde59..549c28f7b 100644 --- a/test/specs/i18n.js +++ b/test/specs/i18n.js @@ -1,5 +1,6 @@ import assert from 'power-assert' import Vue from 'vue' +import compare from '../../src/compare' import locales from './fixture/locales' @@ -198,6 +199,7 @@ describe('i18n', () => { }) + /* describe('reactive translation', () => { it('should translate', done => { const ViewModel = Vue.extend({ @@ -226,31 +228,48 @@ describe('i18n', () => { }) }) }) + */ describe('translate component', () => { it('should translate', done => { - const ViewModel = Vue.extend({ - template: '

{{ $t("message.hello") }}

', + const compOptions = {} + if (compare(Vue.version, '2.0.0-alpha') < 0) { + compOptions.template = '

{{* $t("message.hoge") }}

' + } else { + compOptions.render = function () { + return this.$createElement('p', {}, [this.__toString__(this.$t('message.hoge'))]) + } + } + + const options = { el: () => { const el = document.createElement('div') - el.id = 'translate-parent' document.body.appendChild(el) return el }, - components: { - hoge: { - template: '

{{* $t("message.hoge") }}

' - } + components: { hoge: compOptions } + } + + if (compare(Vue.version, '2.0.0-alpha') < 0) { + options.template = '

{{ $t("message.hello") }}

' + } else { + options.render = function () { + return this.$createElement('div', {}, [ + this.$createElement('p', {}, [this.__toString__(this.$t('message.hello'))]), + this.$createElement('hoge', {}) + ]) } - }) - new ViewModel() + } + + const ViewModel = Vue.extend(options) + const vm = new ViewModel() Vue.nextTick(() => { - const child = document.querySelector('#translate-child') + const child = vm.$el.children[1] assert(child.textContent === locales.en.message.hoge) - const parent = document.querySelector('#translate-parent p') + const parent = vm.$el.children[0] assert(parent.textContent === locales.en.message.hello) done()