Skip to content

Commit 045eaa6

Browse files
Merge pull request #4 from makeupsomething/feature/add-additionalOptions-test-example
Add suggested fixes
2 parents 6116585 + 3489e0d commit 045eaa6

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

tests/__tests__/components/VueI18n.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<template>
22
<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')">
3+
<h2>{{ $t('Hello') }}</h2>
4+
<button @click="switchLocale('en')">English</button>
5+
<button @click="switchLocale('ja')">
66
Japanese
77
</button>
88
</div>

tests/__tests__/vueI18n.js

+16-9
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,32 @@ import VueI18n from './components/VueI18n'
55

66
afterEach(cleanup)
77

8-
const ja = {
9-
Hello: 'こんにちは'
8+
const messages = {
9+
en: {
10+
Hello: 'Hello'
11+
},
12+
ja: {
13+
Hello: 'こんにちは'
14+
}
1015
}
1116

1217
test('can render en and ja text in header', async () => {
13-
const { queryByTestId, getByTestId } = render(VueI18n, {}, vue => {
18+
const { queryByText, getByText } = render(VueI18n, {}, vue => {
1419
vue.use(Vuei18n)
1520
const i18n = new Vuei18n({
1621
locale: 'en',
17-
messages: {
18-
ja
19-
}
22+
fallbackLocale: 'en',
23+
messages
2024
})
25+
//return i18n object so that it will be available as an additional option on the created vue instance
2126
return { i18n }
2227
})
2328

24-
expect(queryByTestId('section-header')).toHaveTextContent('Hello')
29+
expect(getByText('Hello')).toBeInTheDocument()
2530

26-
await fireEvent.click(getByTestId('button-ja'))
31+
await fireEvent.click(getByText('Japanese'))
2732

28-
expect(queryByTestId('section-header')).toHaveTextContent('こんにちは')
33+
expect(getByText('こんにちは')).toBeInTheDocument()
34+
35+
expect(queryByText('Hello')).toBeNull()
2936
})

0 commit comments

Comments
 (0)