Skip to content

Commit 2c0093c

Browse files
Update vue-i18n example
1 parent 832c2e6 commit 2c0093c

File tree

3 files changed

+40
-55
lines changed

3 files changed

+40
-55
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"vee-validate": "^2.2.15",
7171
"vue": "^3.0.0",
7272
"vue-apollo": "^3.0.4",
73-
"vue-i18n": "^8.21.1",
73+
"vue-i18n": "^9.0.0-beta.4",
7474
"vue-jest": "^5.0.0-alpha.4",
7575
"vue-router": "^3.4.5",
7676
"vuetify": "^2.3.10",
+6-12
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
<template>
2-
<div>
3-
<h2>{{ $t('Hello') }}</h2>
4-
<button @click="switchLocale('en')">English</button>
5-
<button @click="switchLocale('ja')">Japanese</button>
6-
</div>
2+
<h2>{{ $t('hello') }}</h2>
3+
<select v-model="$i18n.locale">
4+
<option value="en">English</option>
5+
<option value="ja">Japanese</option>
6+
</select>
77
</template>
88

99
<script>
1010
export default {
11-
name: 'VueI18n',
12-
13-
methods: {
14-
switchLocale(locale) {
15-
this.$i18n.locale = locale
16-
},
17-
},
11+
name: 'Translations',
1812
}
1913
</script>

src/__tests__/vue-i18n.js

+33-42
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,33 @@
1-
test.todo('Your test suite must contain at least one test.')
2-
3-
// import '@testing-library/jest-dom'
4-
// import {render, fireEvent} from '@testing-library/vue'
5-
// import Vuei18n from 'vue-i18n'
6-
// import Translations from './components/Translations'
7-
8-
// const messages = {
9-
// en: {
10-
// Hello: 'Hello',
11-
// },
12-
// ja: {
13-
// Hello: 'こんにちは',
14-
// },
15-
// }
16-
17-
// test('renders translations', async () => {
18-
// const {queryByText, getByText} = render(Translations, {}, vue => {
19-
// // Let's register and configure Vuei18n normally
20-
// vue.use(Vuei18n)
21-
22-
// const i18n = new Vuei18n({
23-
// locale: 'en',
24-
// fallbackLocale: 'en',
25-
// messages,
26-
// })
27-
28-
// // Notice how we return an object from the callback function. It will be
29-
// // merged as an additional option on the created Vue instance.
30-
// return {
31-
// i18n,
32-
// }
33-
// })
34-
35-
// expect(getByText('Hello')).toBeInTheDocument()
36-
37-
// await fireEvent.click(getByText('Japanese'))
38-
39-
// expect(getByText('こんにちは')).toBeInTheDocument()
40-
41-
// expect(queryByText('Hello')).toBeNull()
42-
// })
1+
import '@testing-library/jest-dom'
2+
import {render, fireEvent} from '@testing-library/vue'
3+
import {createI18n} from 'vue-i18n'
4+
import Translations from './components/Translations'
5+
6+
const i18n = createI18n({
7+
legacy: true,
8+
locale: 'en',
9+
messages: {
10+
en: {
11+
hello: 'Hello',
12+
},
13+
ja: {
14+
hello: 'こんにちは',
15+
},
16+
},
17+
})
18+
19+
test('renders translations', async () => {
20+
const {queryByText, getByText} = render(Translations, {
21+
global: {
22+
plugins: [i18n]
23+
}
24+
})
25+
26+
expect(getByText('Hello')).toBeInTheDocument()
27+
28+
await fireEvent.update(getByText('Japanese'))
29+
30+
expect(getByText('こんにちは')).toBeInTheDocument()
31+
32+
expect(queryByText('Hello')).toBeNull()
33+
})

0 commit comments

Comments
 (0)