File tree 2 files changed +19
-12
lines changed
2 files changed +19
-12
lines changed Original file line number Diff line number Diff line change 1
1
<template >
2
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')" >
3
+ <h2 >{{ $t('Hello') }}</h2 >
4
+ <button @click =" switchLocale('en')" >English</button >
5
+ <button @click =" switchLocale('ja')" >
6
6
Japanese
7
7
</button >
8
8
</div >
Original file line number Diff line number Diff line change @@ -5,25 +5,32 @@ import VueI18n from './components/VueI18n'
5
5
6
6
afterEach ( cleanup )
7
7
8
- const ja = {
9
- Hello : 'こんにちは'
8
+ const messages = {
9
+ en : {
10
+ Hello : 'Hello'
11
+ } ,
12
+ ja : {
13
+ Hello : 'こんにちは'
14
+ }
10
15
}
11
16
12
17
test ( 'can render en and ja text in header' , async ( ) => {
13
- const { queryByTestId , getByTestId } = render ( VueI18n , { } , vue => {
18
+ const { queryByText , getByText } = render ( VueI18n , { } , vue => {
14
19
vue . use ( Vuei18n )
15
20
const i18n = new Vuei18n ( {
16
21
locale : 'en' ,
17
- messages : {
18
- ja
19
- }
22
+ fallbackLocale : 'en' ,
23
+ messages
20
24
} )
25
+ //return i18n object so that it will be available as an additional option on the created vue instance
21
26
return { i18n }
22
27
} )
23
28
24
- expect ( queryByTestId ( 'section-header ') ) . toHaveTextContent ( 'Hello' )
29
+ expect ( getByText ( 'Hello ') ) . toBeInTheDocument ( )
25
30
26
- await fireEvent . click ( getByTestId ( 'button-ja ') )
31
+ await fireEvent . click ( getByText ( 'Japanese ') )
27
32
28
- expect ( queryByTestId ( 'section-header' ) ) . toHaveTextContent ( 'こんにちは' )
33
+ expect ( getByText ( 'こんにちは' ) ) . toBeInTheDocument ( )
34
+
35
+ expect ( queryByText ( 'Hello' ) ) . toBeNull ( )
29
36
} )
You can’t perform that action at this time.
0 commit comments