Skip to content

Commit 024e499

Browse files
committed
updated test case
1 parent 7fc910b commit 024e499

2 files changed

Lines changed: 19 additions & 19 deletions

File tree

src/App.test.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
1-
import { render, screen } from '@testing-library/react';
1+
import { render, screen, fireEvent } from '@testing-library/react';
22
import { describe, it, expect } from 'vitest';
33
import App from './App';
44

55
describe('App', () => {
66
it('renders headline', () => {
77
render(<App />);
8-
const headline = screen.getByText(/Vite \+ React/i);
8+
const headline = screen.getByText(/count is/i);
99
expect(headline).toBeInTheDocument();
1010
});
11+
12+
it('increments count on button click', () => {
13+
render(<App />);
14+
const button = screen.getByText(/count is/i);
15+
fireEvent.click(button);
16+
const updatedButton = screen.getByText(/count is 1/i);
17+
expect(updatedButton).toBeInTheDocument();
18+
});
19+
20+
it('increments count on multiple button clicks', () => {
21+
render(<App />);
22+
const button = screen.getByText(/count is/i);
23+
fireEvent.click(button);
24+
fireEvent.click(button);
25+
const updatedButton = screen.getByText(/count is 2/i);
26+
expect(updatedButton).toBeInTheDocument();
27+
});
1128
});

src/App.tsx

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,16 @@
11
import { useState } from 'react'
2-
import reactLogo from './assets/react.svg'
3-
import viteLogo from './assets/vite.svg'
42
import './App.css'
53

64
function 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
}

0 commit comments

Comments
 (0)