Skip to content

Commit 6116585

Browse files
Merge pull request #3 from makeupsomething/develop
Develop
2 parents 7a4b35e + ab00d3c commit 6116585

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-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 data-testid="section-header">{{ $t('Hello') }}</h2>
4+
<button data-testid="button-en" @click="switchLocale('en')">English</button>
5+
<button data-testid="button-ja" @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

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 ja = {
9+
Hello: 'こんにちは'
10+
}
11+
12+
test('can render en and ja text in header', async () => {
13+
const { queryByTestId, getByTestId } = render(VueI18n, {}, vue => {
14+
vue.use(Vuei18n)
15+
const i18n = new Vuei18n({
16+
locale: 'en',
17+
messages: {
18+
ja
19+
}
20+
})
21+
return { i18n }
22+
})
23+
24+
expect(queryByTestId('section-header')).toHaveTextContent('Hello')
25+
26+
await fireEvent.click(getByTestId('button-ja'))
27+
28+
expect(queryByTestId('section-header')).toHaveTextContent('こんにちは')
29+
})

0 commit comments

Comments
 (0)