File tree Expand file tree Collapse file tree 2 files changed +19
-12
lines changed Expand file tree Collapse file tree 2 files changed +19
-12
lines changed Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff line change @@ -5,25 +5,32 @@ import VueI18n from './components/VueI18n'
55
66afterEach ( cleanup )
77
8- const ja = {
9- Hello : 'こんにちは'
8+ const messages = {
9+ en : {
10+ Hello : 'Hello'
11+ } ,
12+ ja : {
13+ Hello : 'こんにちは'
14+ }
1015}
1116
1217test ( '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} )
You can’t perform that action at this time.
0 commit comments