Skip to content

Commit 3632f9e

Browse files
committed
test: Cleanup
1 parent a6c0d22 commit 3632f9e

File tree

4 files changed

+28
-63
lines changed

4 files changed

+28
-63
lines changed

jest.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ module.exports = {
1111
transform: {
1212
'^.+\\js$': 'babel-jest'
1313
},
14-
moduleFileExtensions: ['vue', 'js', 'json', 'jsx', 'ts', 'tsx', 'node']
14+
moduleFileExtensions: ['vue', 'js', 'json', 'jsx', 'ts', 'tsx', 'node'],
15+
setupFiles: [path.resolve(__dirname, './test/setup.ts')]
1516
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"name": "laravel-vue-i18n",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"author": {
55
"name": "Francisco Madeira",
66
"email": "[email protected]"
77
},
8+
"keywords": "laravel, vue, vue3, inertiajs",
89
"repository": "https://github.com/xico2k/laravel-vue-i18n",
910
"license": "MIT",
1011
"description": "allows to connect your `Laravel` Framework localization files with `Vue`.",

test/plugin.spec.ts

Lines changed: 7 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,101 +2,47 @@ import { mount } from '@vue/test-utils'
22
import { i18nVue, trans, loadLanguageAsync } from '../src'
33

44
it('translates with $t mixin', async () => {
5-
const wrapper = mount({ template: `<h1>{{ $t('Welcome!') }}</h1>` }, {
6-
global: {
7-
plugins: [[i18nVue, {
8-
lang: 'pt',
9-
resolve: lang => import(`./fixtures/lang/${lang}.json`),
10-
}]]
11-
}
12-
});
5+
const wrapper = await global.mountPlugin(`<h1 v-text="$t('Welcome!')" />`);
136

14-
await new Promise(resolve => setTimeout(resolve))
157
expect(wrapper.html()).toBe('<h1>Bem-vindo!</h1>')
168
})
179

1810
it('translates with "trans" helper', async () => {
19-
const wrapper = mount({ template: '<div />' }, {
20-
global: {
21-
plugins: [[i18nVue, {
22-
lang: 'pt',
23-
resolve: lang => import(`./fixtures/lang/${lang}.json`),
24-
}]]
25-
}
26-
});
11+
const wrapper = await global.mountPlugin();
2712

28-
await new Promise(resolve => setTimeout(resolve))
2913
expect(trans('Welcome!')).toBe('Bem-vindo!');
3014
})
3115

3216
it('returns the same string given if it is not found on the lang file', async () => {
33-
const wrapper = mount({ template: `<h1>{{ $t('This has no translation') }}</h1>` }, {
34-
global: {
35-
plugins: [[i18nVue, {
36-
lang: 'pt',
37-
resolve: lang => import(`./fixtures/lang/${lang}.json`),
38-
}]]
39-
}
40-
});
17+
const wrapper = await global.mountPlugin(`<h1>{{ $t('This has no translation') }}</h1>`);
4118

42-
await new Promise(resolve => setTimeout(resolve))
4319
expect(wrapper.html()).toBe('<h1>This has no translation</h1>')
4420
})
4521

4622
it('returns the given key if the key is not available on the lang', async () => {
47-
const wrapper = mount({ template: `<div />` }, {
48-
global: {
49-
plugins: [[i18nVue, {
50-
lang: 'en',
51-
resolve: lang => import(`./fixtures/lang/${lang}.json`),
52-
}]]
53-
}
54-
});
23+
const wrapper = await global.mountPlugin(`<div />`, 'en');
5524

56-
await new Promise(resolve => setTimeout(resolve))
5725
expect(trans('Only Available on EN')).toBe('Only Available on EN');
5826

5927
await loadLanguageAsync('pt');
6028
expect(trans('Only Available on EN')).toBe('Only Available on EN');
6129
})
6230

6331
it('translates key with values with $t mixin', async () => {
64-
const wrapper = mount({ template: `<h1>{{ $t('Welcome, :name!', { name: 'Francisco' }) }}</h1>` }, {
65-
global: {
66-
plugins: [[i18nVue, {
67-
lang: 'pt',
68-
resolve: lang => import(`./fixtures/lang/${lang}.json`),
69-
}]]
70-
}
71-
});
32+
const wrapper = await global.mountPlugin(`<h1>{{ $t('Welcome, :name!', { name: 'Francisco' }) }}</h1>`);
7233

73-
await new Promise(resolve => setTimeout(resolve))
7434
expect(wrapper.html()).toBe('<h1>Bem-vindo, Francisco!</h1>')
7535
})
7636

7737
it('translates key with values with "trans" helper', async () => {
78-
const wrapper = mount({ template: '<div />' }, {
79-
global: {
80-
plugins: [[i18nVue, {
81-
lang: 'pt',
82-
resolve: lang => import(`./fixtures/lang/${lang}.json`),
83-
}]]
84-
}
85-
});
38+
const wrapper = await global.mountPlugin();
8639

87-
await new Promise(resolve => setTimeout(resolve))
8840
expect(trans('Welcome, :name!', { name: 'Francisco' }))
8941
.toBe('Bem-vindo, Francisco!')
9042
})
9143

9244
it('loads a lang', async () => {
93-
const wrapper = mount({ template: `<h1>{{ $t('Welcome, :name!', { name: 'Francisco' }) }}</h1>` }, {
94-
global: {
95-
plugins: [[i18nVue, {
96-
resolve: lang => import(`./fixtures/lang/${lang}.json`),
97-
}]]
98-
}
99-
});
45+
const wrapper = await global.mountPlugin(`<h1>{{ $t('Welcome, :name!', { name: 'Francisco' }) }}</h1>`, 'en');
10046

10147
await loadLanguageAsync('pt');
10248
expect(wrapper.html()).toBe('<h1>Bem-vindo, Francisco!</h1>')

test/setup.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { mount } from '@vue/test-utils'
2+
import { i18nVue } from '../src'
3+
4+
global.mountPlugin = async (template = '<div />', lang = 'pt') => {
5+
const wrapper = mount({ template }, {
6+
global: {
7+
plugins: [[i18nVue, {
8+
lang,
9+
resolve: lang => import(`./fixtures/lang/${lang}.json`),
10+
}]]
11+
}
12+
});
13+
14+
await new Promise(resolve => setTimeout(resolve))
15+
16+
return wrapper;
17+
}

0 commit comments

Comments
 (0)