Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8bdc12e

Browse files
1 parent 77cae69 commit 8bdc12e

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Component, Input } from '@angular/core';
2+
import { render, screen, fireEvent } from '@testing-library/angular';
3+
4+
@Component({
5+
selector: 'app-root',
6+
template: ` <button (click)="decrement()">-</button>
7+
<span data-testid="count">Current Count: {{ counter }}</span>
8+
<button (click)="increment()">+</button>`,
9+
})
10+
class AppComponent {
11+
@Input() counter = 0;
12+
13+
increment() {
14+
this.counter += 1;
15+
}
16+
17+
decrement() {
18+
this.counter -= 1;
19+
}
20+
}
21+
22+
describe('Counter', () => {
23+
it('should render counter', async () => {
24+
await render(AppComponent, {
25+
componentProperties: { counter: 5 },
26+
});
27+
28+
expect(screen.getByText('Current Count: 5')).toBeInTheDocument();
29+
});
30+
31+
it('should increment the counter on click', async () => {
32+
await render(AppComponent, {
33+
componentProperties: { counter: 5 },
34+
});
35+
36+
fireEvent.click(screen.getByText('+'));
37+
38+
expect(screen.getByText('Current Count: 6')).toBeInTheDocument();
39+
});
40+
});

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /