Skip to content

Commit 2850a21

Browse files
authored
Merge pull request #58 from makeupsomething/master
Add additionalOptions test example
2 parents 59669db + 045eaa6 commit 2850a21

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"lint-staged": "^8.1.7",
6565
"prettier": "^1.17.1",
6666
"vee-validate": "^2.2.9",
67+
"vue-i18n": "^8.12.0",
6768
"vue-jest": "^3.0.4",
6869
"vue-router": "^3.0.6",
6970
"vuex": "^3.1.1"
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<template>
2+
<div>
3+
<h2>{{ $t('Hello') }}</h2>
4+
<button @click="switchLocale('en')">English</button>
5+
<button @click="switchLocale('ja')">
6+
Japanese
7+
</button>
8+
</div>
9+
</template>
10+
11+
<script>
12+
export default {
13+
name: 'VueI18n',
14+
15+
methods: {
16+
switchLocale(locale) {
17+
this.$i18n.locale = locale
18+
}
19+
}
20+
}
21+
</script>

tests/__tests__/vueI18n.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import 'jest-dom/extend-expect'
2+
import { cleanup, render, fireEvent } from '@testing-library/vue'
3+
import Vuei18n from 'vue-i18n'
4+
import VueI18n from './components/VueI18n'
5+
6+
afterEach(cleanup)
7+
8+
const messages = {
9+
en: {
10+
Hello: 'Hello'
11+
},
12+
ja: {
13+
Hello: 'こんにちは'
14+
}
15+
}
16+
17+
test('can render en and ja text in header', async () => {
18+
const { queryByText, getByText } = render(VueI18n, {}, vue => {
19+
vue.use(Vuei18n)
20+
const i18n = new Vuei18n({
21+
locale: 'en',
22+
fallbackLocale: 'en',
23+
messages
24+
})
25+
//return i18n object so that it will be available as an additional option on the created vue instance
26+
return { i18n }
27+
})
28+
29+
expect(getByText('Hello')).toBeInTheDocument()
30+
31+
await fireEvent.click(getByText('Japanese'))
32+
33+
expect(getByText('こんにちは')).toBeInTheDocument()
34+
35+
expect(queryByText('Hello')).toBeNull()
36+
})

0 commit comments

Comments
 (0)