File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
apps/example-app/src/app/issues Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change
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
+ } ) ;
You can’t perform that action at this time.
0 commit comments