@@ -19,43 +19,23 @@ export class CounterComponent {
19
19
}
20
20
}
21
21
22
- test ( 'Counter actions' , async ( ) => {
22
+ test ( 'Counter actions via template syntax ' , async ( ) => {
23
23
const { detectChanges, getByText, getByTestId } = await createComponent ( '<counter [counter]="10"></counter>' , {
24
24
declarations : [ CounterComponent ] ,
25
25
} ) ;
26
26
27
- getByText ( '+' ) . click ( ) ;
28
- getByText ( '+' ) . click ( ) ;
29
- getByText ( '+' ) . click ( ) ;
30
- detectChanges ( ) ;
31
- expect ( getByText ( 'Current Count: 13' ) ) . toBeTruthy ( ) ;
32
- expect ( getByTestId ( 'count' ) . textContent ) . toBe ( 'Current Count: 13' ) ;
33
-
34
- getByText ( '-' ) . click ( ) ;
35
- detectChanges ( ) ;
36
- expect ( getByText ( 'Current Count: 12' ) ) . toBeTruthy ( ) ;
37
- expect ( getByTestId ( 'count' ) . textContent ) . toBe ( 'Current Count: 12' ) ;
38
- } ) ;
39
-
40
- test ( 'Counter actions - fireEvent' , async ( ) => {
41
- const { detectChanges, getByText, getByTestId } = await createComponent ( '<counter [counter]="10"></counter>' , {
42
- declarations : [ CounterComponent ] ,
43
- } ) ;
44
-
45
- fireEvent . click ( getByText ( '+' ) ) ;
46
- fireEvent . click ( getByText ( '+' ) ) ;
47
27
fireEvent . click ( getByText ( '+' ) ) ;
48
28
detectChanges ( ) ;
49
- expect ( getByText ( 'Current Count: 13 ' ) ) . toBeTruthy ( ) ;
50
- expect ( getByTestId ( 'count' ) . textContent ) . toBe ( 'Current Count: 13 ' ) ;
29
+ expect ( getByText ( 'Current Count: 11 ' ) ) . toBeTruthy ( ) ;
30
+ expect ( getByTestId ( 'count' ) . textContent ) . toBe ( 'Current Count: 11 ' ) ;
51
31
52
- fireEvent . click ( getByText ( '-' ) ) ;
32
+ getByText ( '-' ) . click ( ) ;
53
33
detectChanges ( ) ;
54
- expect ( getByText ( 'Current Count: 12 ' ) ) . toBeTruthy ( ) ;
55
- expect ( getByTestId ( 'count' ) . textContent ) . toBe ( 'Current Count: 12 ' ) ;
34
+ expect ( getByText ( 'Current Count: 10 ' ) ) . toBeTruthy ( ) ;
35
+ expect ( getByTestId ( 'count' ) . textContent ) . toBe ( 'Current Count: 10 ' ) ;
56
36
} ) ;
57
37
58
- test ( 'Counter actions via component' , async ( ) => {
38
+ test ( 'Counter actions via component syntax ' , async ( ) => {
59
39
const { getComponentInstance } = await createComponent (
60
40
{
61
41
component : CounterComponent ,
@@ -70,15 +50,13 @@ test('Counter actions via component', async () => {
70
50
71
51
const counter = getComponentInstance ( ) ;
72
52
counter . increment ( ) ;
73
- counter . increment ( ) ;
74
- counter . increment ( ) ;
75
- expect ( counter . counter ) . toBe ( 13 ) ;
53
+ expect ( counter . counter ) . toBe ( 11 ) ;
76
54
77
55
counter . decrement ( ) ;
78
- expect ( counter . counter ) . toBe ( 12 ) ;
56
+ expect ( counter . counter ) . toBe ( 10 ) ;
79
57
} ) ;
80
58
81
- test ( 'Counter actions via component without parameters' , async ( ) => {
59
+ test ( 'Counter actions via component syntax without parameters' , async ( ) => {
82
60
const { getComponentInstance } = await createComponent (
83
61
{
84
62
component : CounterComponent ,
@@ -90,15 +68,13 @@ test('Counter actions via component without parameters', async () => {
90
68
91
69
const counter = getComponentInstance ( ) ;
92
70
counter . increment ( ) ;
93
- counter . increment ( ) ;
94
- counter . increment ( ) ;
95
- expect ( counter . counter ) . toBe ( 3 ) ;
71
+ expect ( counter . counter ) . toBe ( 1 ) ;
96
72
97
73
counter . decrement ( ) ;
98
- expect ( counter . counter ) . toBe ( 2 ) ;
74
+ expect ( counter . counter ) . toBe ( 0 ) ;
99
75
} ) ;
100
76
101
- test ( 'Counter via component - test template ' , async ( ) => {
77
+ test ( 'Counter actions via component syntax and dom-testing-library functions ' , async ( ) => {
102
78
const { getByText, detectChanges, getByTestId } = await createComponent (
103
79
{
104
80
component : CounterComponent ,
@@ -111,15 +87,13 @@ test('Counter via component - test template', async () => {
111
87
} ,
112
88
) ;
113
89
114
- getByText ( '+' ) . click ( ) ;
115
- getByText ( '+' ) . click ( ) ;
116
90
getByText ( '+' ) . click ( ) ;
117
91
detectChanges ( ) ;
118
- expect ( getByText ( 'Current Count: 13 ' ) ) . toBeTruthy ( ) ;
119
- expect ( getByTestId ( 'count' ) . textContent ) . toBe ( 'Current Count: 13 ' ) ;
92
+ expect ( getByText ( 'Current Count: 11 ' ) ) . toBeTruthy ( ) ;
93
+ expect ( getByTestId ( 'count' ) . textContent ) . toBe ( 'Current Count: 11 ' ) ;
120
94
121
95
getByText ( '-' ) . click ( ) ;
122
96
detectChanges ( ) ;
123
- expect ( getByText ( 'Current Count: 12 ' ) ) . toBeTruthy ( ) ;
124
- expect ( getByTestId ( 'count' ) . textContent ) . toBe ( 'Current Count: 12 ' ) ;
97
+ expect ( getByText ( 'Current Count: 10 ' ) ) . toBeTruthy ( ) ;
98
+ expect ( getByTestId ( 'count' ) . textContent ) . toBe ( 'Current Count: 10 ' ) ;
125
99
} ) ;
0 commit comments