1
- /*
2
- import test from 'ava'
3
- import sinon from 'sinon'
4
- import Vue from 'vue'
5
- import VueI18n from 'vue-i18n'
6
- import { compile } from 'vue-template-compiler'
7
- import { module } from '../src/index'
1
+ const VueI18n = require ( 'vue-i18n' )
2
+ const { createLocalVue } = require ( '@vue/test-utils' )
3
+ const { compile } = require ( 'vue-template-compiler' )
4
+ const I18nModule = require ( '../src/index' ) . module
8
5
6
+ const Vue = createLocalVue ( )
9
7
Vue . use ( VueI18n )
10
8
11
9
const options = {
@@ -23,58 +21,62 @@ const options = {
23
21
}
24
22
25
23
const i18n = new VueI18n ( options )
26
- const i18nModule = module (i18n)
24
+ const i18nModule = I18nModule ( i18n )
27
25
28
- test ('transform with static string literal', t => {
26
+ it ( 'transform with static string literal' , ( ) => {
29
27
const { ast, render, errors } = compile ( `<p v-t="'hello'"></p>` , { modules : [ i18nModule ] } )
30
- t.is (ast.i18n, 'hello')
31
- t.is (render, `with(this){return _c('p',{domProps:{"textContent":_s("hello")}}) }`)
32
- t.deepEqual (errors, [])
28
+ expect ( ast . i18n ) . toEqual ( 'hello' )
29
+ expect ( render ) . toEqual ( `with(this){return _c('p',{domProps:{"textContent":_s("hello")}})}` )
30
+ expect ( errors ) . toEqual ( [ ] )
33
31
} )
34
32
35
- test ('transform with static object literal', t => {
33
+ it ( 'transform with static object literal' , ( ) => {
36
34
const { ast, render, errors } = compile ( `<p v-t="{ path: 'named', locale: 'ja', args: { name: 'kazupon' } }"></p>` , { modules : [ i18nModule ] } )
37
- t.is (ast.i18n, 'やあ、kazupon!')
38
- t.is (render, `with(this){return _c('p',{domProps:{"textContent":_s("やあ、kazupon!")}}) }`)
39
- t.deepEqual (errors, [])
35
+ expect ( ast . i18n ) . toEqual ( 'やあ、kazupon!' )
36
+ expect ( render ) . toEqual ( `with(this){return _c('p',{domProps:{"textContent":_s("やあ、kazupon!")}})}` )
37
+ expect ( errors ) . toEqual ( [ ] )
40
38
} )
41
39
42
- test('not transform with dynamic params', t => {
43
- const spy = sinon.spy(console, 'warn')
40
+ it ( 'not transform with dynamic params' , ( ) => {
41
+ const spy = jest . spyOn ( global . console , 'warn' )
42
+ spy . mockImplementation ( x => x )
44
43
const { ast, render, errors } = compile ( `<p v-t="hello"></p>` , { modules : [ i18nModule ] } )
45
- t.falsy(ast.i18n)
46
- t.is(render, `with(this){return _c('p',{directives:[{name:"t",rawName:"v-t",value:(hello),expression:"hello"}]}) }`)
47
- t.deepEqual(errors, [])
48
- t.truthy(spy.withArgs('[vue-i18n-extensions] pre-localization with v-t support only static params').calledOnce)
49
- spy.restore()
44
+ expect ( ast . i18n ) . toBeFalsy ( )
45
+ expect ( render ) . toEqual ( `with(this){return _c('p',{directives:[{name:"t",rawName:"v-t",value:(hello),expression:"hello"}]})}` )
46
+ expect ( errors ) . toEqual ( [ ] )
47
+ expect ( spy . mock . calls [ 0 ] [ 0 ] ) . toEqual ( '[vue-i18n-extensions] pre-localization with v-t support only static params' )
48
+ spy . mockReset ( )
49
+ spy . mockRestore ( )
50
50
} )
51
51
52
- test('not support value warning', t => {
53
- const spy = sinon.spy(console, 'warn')
52
+ it ( 'not support value warning' , ( ) => {
53
+ const spy = jest . spyOn ( global . console , 'warn' )
54
+ spy . mockImplementation ( x => x )
54
55
const { ast, render, errors } = compile ( `<p v-t="[1]"></p>` , { modules : [ i18nModule ] } )
55
- t.falsy(ast.i18n)
56
- t.is(render, `with(this){return _c('p',{directives:[{name:"t",rawName:"v-t",value:([1]),expression:"[1]"}]}) }`)
57
- t.deepEqual(errors, [])
58
- t.truthy(spy.withArgs('[vue-i18n-extensions] not support value type').calledOnce)
59
- spy.restore()
56
+ expect ( ast . i18n ) . toBeFalsy ( )
57
+ expect ( render ) . toEqual ( `with(this){return _c('p',{directives:[{name:"t",rawName:"v-t",value:([1]),expression:"[1]"}]})}` )
58
+ expect ( errors ) . toEqual ( [ ] )
59
+ expect ( spy . mock . calls [ 0 ] [ 0 ] ) . toEqual ( '[vue-i18n-extensions] not support value type' )
60
+ spy . mockReset ( )
61
+ spy . mockRestore ( )
60
62
} )
61
63
62
- test ('detect missing translation', t => {
64
+ it ( 'detect missing translation' , done => {
63
65
i18n . missing = ( locale , key , vm ) => {
64
- t.is(locale, 'en')
65
- t.is(key, 'foo.bar')
66
- t.is(vm, null)
66
+ expect ( locale ) . toEqual ( 'en' )
67
+ expect ( key ) . toEqual ( 'foo.bar' )
68
+ expect ( vm ) . toBeNull ( )
69
+ done ( )
67
70
}
68
71
const { ast, render, errors } = compile ( `<p v-t="'foo.bar'"></p>` , { modules : [ i18nModule ] } )
69
- t.is (ast.i18n, 'foo.bar')
70
- t.is (render, `with(this){return _c(\'p\',{domProps:{"textContent":_s("foo.bar")}}) }`)
71
- t.deepEqual (errors, [])
72
+ expect ( ast . i18n ) . toEqual ( 'foo.bar' )
73
+ expect ( render ) . toEqual ( `with(this){return _c(\'p\',{domProps:{"textContent":_s("foo.bar")}})}` )
74
+ expect ( errors ) . toEqual ( [ ] )
72
75
} )
73
76
74
- test ('fallback custom directive', t => {
77
+ it ( 'fallback custom directive' , ( ) => {
75
78
const { ast, render, errors } = compile ( `<p v-t="'foo.bar'"></p>` )
76
- t.falsy(ast.i18n)
77
- t.deepEqual(ast.directives[0], { name: 't', rawName: 'v-t', value: '\'foo.bar\'', arg: null, modifiers: undefined })
78
- t.deepEqual(errors, [])
79
- })
80
- */
79
+ expect ( ast . i18n ) . toBeFalsy ( )
80
+ expect ( ast . directives [ 0 ] ) . toEqual ( { name : 't' , rawName : 'v-t' , value : '\'foo.bar\'' , arg : null , modifiers : undefined } )
81
+ expect ( errors ) . toEqual ( [ ] )
82
+ } )
0 commit comments