File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import { render , screen } from '@testing-library/react' ;
1+ import { render , screen , fireEvent } from '@testing-library/react' ;
22import { describe , it , expect } from 'vitest' ;
33import App from './App' ;
44
55describe ( 'App' , ( ) => {
66 it ( 'renders headline' , ( ) => {
77 render ( < App /> ) ;
8- const headline = screen . getByText ( / V i t e \+ R e a c t / i) ;
8+ const headline = screen . getByText ( / c o u n t i s / i) ;
99 expect ( headline ) . toBeInTheDocument ( ) ;
1010 } ) ;
11+
12+ it ( 'increments count on button click' , ( ) => {
13+ render ( < App /> ) ;
14+ const button = screen . getByText ( / c o u n t i s / i) ;
15+ fireEvent . click ( button ) ;
16+ const updatedButton = screen . getByText ( / c o u n t i s 1 / i) ;
17+ expect ( updatedButton ) . toBeInTheDocument ( ) ;
18+ } ) ;
19+
20+ it ( 'increments count on multiple button clicks' , ( ) => {
21+ render ( < App /> ) ;
22+ const button = screen . getByText ( / c o u n t i s / i) ;
23+ fireEvent . click ( button ) ;
24+ fireEvent . click ( button ) ;
25+ const updatedButton = screen . getByText ( / c o u n t i s 2 / i) ;
26+ expect ( updatedButton ) . toBeInTheDocument ( ) ;
27+ } ) ;
1128} ) ;
Original file line number Diff line number Diff line change 11import { useState } from 'react'
2- import reactLogo from './assets/react.svg'
3- import viteLogo from './assets/vite.svg'
42import './App.css'
53
64function App ( ) {
75 const [ count , setCount ] = useState ( 0 )
86
97 return (
108 < >
11- < div >
12- < a href = "https://vite.dev" target = "_blank" >
13- < img src = { viteLogo } className = "logo" alt = "Vite logo" />
14- </ a >
15- < a href = "https://react.dev" target = "_blank" >
16- < img src = { reactLogo } className = "logo react" alt = "React logo" />
17- </ a >
18- </ div >
19- < h1 > Vite + React</ h1 >
209 < div className = "card" >
2110 < button onClick = { ( ) => setCount ( ( count ) => count + 1 ) } >
2211 count is { count }
2312 </ button >
24- < p >
25- Edit < code > src/App.tsx</ code > and save to test HMR
26- </ p >
2713 </ div >
28- < p className = "read-the-docs" >
29- Click on the Vite and React logos to learn more
30- </ p >
3114 </ >
3215 )
3316}
You can’t perform that action at this time.
0 commit comments