Skip to content

Commit 06bd634

Browse files
committed
👕 refactor(test): switch to jest
1 parent c891ce0 commit 06bd634

File tree

2 files changed

+47
-44
lines changed

2 files changed

+47
-44
lines changed

test/directive.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
const Vue = require('vue')
21
const VueI18n = require('vue-i18n')
2+
const { createLocalVue } = require('@vue/test-utils')
33
const { createRenderer } = require('vue-server-renderer')
44
const { directive } = require('../src/index')
55

6+
const Vue = createLocalVue()
67
Vue.use(VueI18n)
78

89
const options = {

test/module.test.js

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
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
85

6+
const Vue = createLocalVue()
97
Vue.use(VueI18n)
108

119
const options = {
@@ -23,58 +21,62 @@ const options = {
2321
}
2422

2523
const i18n = new VueI18n(options)
26-
const i18nModule = module(i18n)
24+
const i18nModule = I18nModule(i18n)
2725

28-
test('transform with static string literal', t => {
26+
it('transform with static string literal', () => {
2927
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([])
3331
})
3432

35-
test('transform with static object literal', t => {
33+
it('transform with static object literal', () => {
3634
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([])
4038
})
4139

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)
4443
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()
5050
})
5151

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)
5455
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()
6062
})
6163

62-
test('detect missing translation', t => {
64+
it('detect missing translation', done => {
6365
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()
6770
}
6871
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([])
7275
})
7376

74-
test('fallback custom directive', t => {
77+
it('fallback custom directive', () => {
7578
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

Comments
 (0)