1- import { mount } from '@vue/test-utils'
1+ import { mount , createLocalVue } from '@vue/test-utils'
22import TypeScript from './components/TypeScript.vue'
33import { resolve } from 'path'
44import { readFileSync } from 'fs'
5+ import VueI18n from 'vue-i18n'
56import jestVue from 'vue-jest'
67import RenderFunction from './components/RenderFunction.vue'
78import Jade from './components/Jade.vue'
@@ -12,6 +13,10 @@ import { randomExport } from './components/NamedExport.vue'
1213import Coffee from './components/Coffee.vue'
1314import CoffeeScript from './components/CoffeeScript.vue'
1415import FunctionalSFCParent from './components/FunctionalSFCParent.vue'
16+ import I18nJSONInline from './components/I18nJSONInline.vue'
17+ import I18nJSONFromSrc from './components/I18nJSONFromSrc.vue'
18+ import I18nYamlInline from './components/I18nYamlInline.vue'
19+ import I18nMergingMultipleBlocks from './components/I18nMergingMultipleBlocks.vue'
1520import NoScript from './components/NoScript.vue'
1621import Pug from './components/Pug.vue'
1722import PugRelative from './components/PugRelativeExtends.vue'
@@ -125,3 +130,42 @@ test('processes SFC with no template', () => {
125130 const wrapper = mount ( RenderFunction )
126131 expect ( wrapper . is ( 'section' ) ) . toBe ( true )
127132} )
133+
134+ describe ( 'I18n Processor' , ( ) => {
135+ const setup = ( opts = { locale : 'en' } ) => {
136+ const localVue = createLocalVue ( )
137+ localVue . use ( VueI18n )
138+ const i18n = new VueI18n ( opts )
139+ return { i18n, localVue }
140+ }
141+
142+ test ( 'processes SFC with i18n JSON inline custom block' , ( ) => {
143+ const { i18n, localVue } = setup ( )
144+ const wrapper = mount ( I18nJSONInline , { i18n, localVue } )
145+ expect ( wrapper . text ( ) ) . toBe ( 'Hello i18n in SFC!' )
146+ expect ( wrapper ) . toMatchSnapshot ( )
147+ } )
148+
149+ test ( 'processes SFC with i18n JSON in external src attribute' , ( ) => {
150+ const { i18n, localVue } = setup ( )
151+ const wrapper = mount ( I18nJSONFromSrc , { i18n, localVue } )
152+ expect ( wrapper . text ( ) ) . toBe ( 'Hello i18n in SFC!' )
153+ expect ( wrapper ) . toMatchSnapshot ( )
154+ } )
155+
156+ test ( 'processes SFC with i18n Yaml Inline' , ( ) => {
157+ const { i18n, localVue } = setup ( )
158+ const wrapper = mount ( I18nYamlInline , { i18n, localVue } )
159+ expect ( wrapper . text ( ) ) . toBe ( 'hello world!' )
160+ expect ( wrapper ) . toMatchSnapshot ( )
161+ } )
162+
163+ test ( 'merges data blocks' , ( ) => {
164+ const { i18n, localVue } = setup ( )
165+ const wrapper = mount ( I18nMergingMultipleBlocks , { i18n, localVue } )
166+ expect ( wrapper . text ( ) ) . toBe ( 'hello world!' )
167+ expect ( typeof wrapper . vm . $t ( 'additionalKey' ) ) . toEqual ( 'string' )
168+
169+ expect ( wrapper ) . toMatchSnapshot ( )
170+ } )
171+ } )
0 commit comments