@@ -11,6 +11,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
11
11
import { FormsModule , NgForm } from '@angular/forms' ;
12
12
import { By } from '@angular/platform-browser' ;
13
13
import { IntlTelInputComponent } from './intl-tel-input.component' ;
14
+ import { provideExperimentalZonelessChangeDetection } from "@angular/core" ;
14
15
15
16
describe ( 'IntlTelInputComponent' , ( ) => {
16
17
let component : IntlTelInputComponent ;
@@ -24,6 +25,7 @@ describe('IntlTelInputComponent', () => {
24
25
] ,
25
26
providers : [
26
27
NgForm ,
28
+ provideExperimentalZonelessChangeDetection ( ) ,
27
29
]
28
30
} )
29
31
. compileComponents ( ) ;
@@ -32,30 +34,31 @@ describe('IntlTelInputComponent', () => {
32
34
beforeEach ( ( ) => {
33
35
fixture = TestBed . createComponent ( IntlTelInputComponent ) ;
34
36
component = fixture . componentInstance ;
35
- fixture . detectChanges ( ) ;
36
37
} ) ;
37
38
38
39
it ( 'should create' , ( ) => {
39
40
expect ( component ) . toBeTruthy ( ) ;
40
41
} ) ;
41
42
42
- it ( 'should convert phone number to E164 format' , ( ) => {
43
+ it ( 'should convert phone number to E164 format' , async ( ) => {
43
44
fixture . componentRef . setInput ( 'options' , {
44
45
preferredCountries : [ 'ch' ] ,
45
46
onlyCountries : [ 'ch' , 'fr' ]
46
47
} ) ;
48
+ await fixture . whenStable ( ) ;
47
49
component . ngAfterViewInit ( ) ;
48
50
49
51
component . phoneNumber = '0797703808' ;
50
52
51
53
expect ( component . E164PhoneNumber ( ) ) . toBe ( '+41797703808' ) ;
52
54
} ) ;
53
55
54
- it ( 'should re-set E164 phone number on countryChange' , ( ) => {
56
+ it ( 'should re-set E164 phone number on countryChange' , async ( ) => {
55
57
fixture . componentRef . setInput ( 'options' , {
56
58
preferredCountries : [ 'ch' ] ,
57
59
onlyCountries : [ 'ch' , 'fr' ]
58
60
} ) ;
61
+ await fixture . whenStable ( ) ;
59
62
component . ngAfterViewInit ( ) ;
60
63
61
64
component . phoneNumber = '0797703808' ;
@@ -68,10 +71,10 @@ describe('IntlTelInputComponent', () => {
68
71
expect ( component . E164PhoneNumber ( ) ) . toBe ( '+33681215656' ) ;
69
72
} ) ;
70
73
71
- it ( 'should add a label tag if label attribute is set' , ( ) => {
74
+ it ( 'should add a label tag if label attribute is set' , async ( ) => {
72
75
const labelText = 'label text' ;
73
76
fixture . componentRef . setInput ( 'label' , labelText ) ;
74
- fixture . detectChanges ( ) ;
77
+ await fixture . whenStable ( ) ;
75
78
76
79
const element = fixture
77
80
. debugElement
@@ -90,9 +93,9 @@ describe('IntlTelInputComponent', () => {
90
93
expect ( element ) . toBeNull ( ) ;
91
94
} ) ;
92
95
93
- it ( 'should not have a css class by default for the label' , ( ) => {
96
+ it ( 'should not have a css class by default for the label' , async ( ) => {
94
97
fixture . componentRef . setInput ( 'label' , 'label' ) ;
95
- fixture . detectChanges ( ) ;
98
+ await fixture . whenStable ( ) ;
96
99
97
100
const element = fixture
98
101
. debugElement
@@ -102,10 +105,10 @@ describe('IntlTelInputComponent', () => {
102
105
expect ( element . className ) . toBeFalsy ( ) ;
103
106
} ) ;
104
107
105
- it ( 'should be possible to specify a css class for the label' , ( ) => {
108
+ it ( 'should be possible to specify a css class for the label' , async ( ) => {
106
109
fixture . componentRef . setInput ( 'label' , 'label' ) ;
107
110
fixture . componentRef . setInput ( 'labelCssClass' , 'labelCssClass' ) ;
108
- fixture . detectChanges ( ) ;
111
+ await fixture . whenStable ( ) ;
109
112
110
113
const element = fixture
111
114
. debugElement
@@ -115,10 +118,10 @@ describe('IntlTelInputComponent', () => {
115
118
expect ( element . className ) . toContain ( component . labelCssClass ( ) ) ;
116
119
} ) ;
117
120
118
- it ( 'should set both required and aria-required if specified' , ( ) => {
121
+ it ( 'should set both required and aria-required if specified' , async ( ) => {
119
122
fixture . componentRef . setInput ( 'required' , true ) ;
120
123
121
- fixture . detectChanges ( ) ;
124
+ await fixture . whenStable ( ) ;
122
125
123
126
const element : HTMLElement = fixture
124
127
. debugElement
@@ -129,7 +132,9 @@ describe('IntlTelInputComponent', () => {
129
132
expect ( element . getAttribute ( 'aria-required' ) ) . toBe ( 'true' ) ;
130
133
} ) ;
131
134
132
- it ( 'should set a default name attribute if not specified' , ( ) => {
135
+ it ( 'should set a default name attribute if not specified' , async ( ) => {
136
+ await fixture . whenStable ( ) ;
137
+
133
138
const element : HTMLElement = fixture
134
139
. debugElement
135
140
. query ( By . css ( 'input' ) )
@@ -139,9 +144,9 @@ describe('IntlTelInputComponent', () => {
139
144
expect ( element . getAttribute ( 'name' ) ) . toBe ( element . getAttribute ( 'id' ) ) ;
140
145
} ) ;
141
146
142
- it ( 'should set name and id to the same value' , ( ) => {
147
+ it ( 'should set name and id to the same value' , async ( ) => {
143
148
fixture . componentRef . setInput ( 'name' , 'custom-name' ) ;
144
- fixture . detectChanges ( ) ;
149
+ await fixture . whenStable ( ) ;
145
150
146
151
const element : HTMLElement = fixture
147
152
. debugElement
@@ -152,11 +157,11 @@ describe('IntlTelInputComponent', () => {
152
157
expect ( element . getAttribute ( 'name' ) ) . toBe ( element . getAttribute ( 'id' ) ) ;
153
158
} ) ;
154
159
155
- it ( 'should allow specifying a css class' , ( ) => {
160
+ it ( 'should allow specifying a css class' , async ( ) => {
156
161
const cssClass = 'my-css-class' ;
157
162
fixture . componentRef . setInput ( 'cssClass' , cssClass ) ;
158
163
159
- fixture . detectChanges ( ) ;
164
+ await fixture . whenStable ( ) ;
160
165
161
166
const element : HTMLElement = fixture
162
167
. debugElement
@@ -166,14 +171,16 @@ describe('IntlTelInputComponent', () => {
166
171
expect ( element . className ) . toContain ( cssClass ) ;
167
172
} ) ;
168
173
169
- it ( 'should be possible to set preferredCountries option' , ( ) => {
174
+ it ( 'should be possible to set preferredCountries option' , async ( ) => {
170
175
fixture . componentRef . setInput ( 'options' , {
171
176
countrySearch : false ,
172
177
preferredCountries : [ 'ch' ] ,
173
178
onlyCountries : [ 'ch' ]
174
179
} ) ;
180
+
181
+ await fixture . whenStable ( ) ;
182
+
175
183
component . ngAfterViewInit ( ) ;
176
- fixture . detectChanges ( ) ;
177
184
178
185
const element = fixture
179
186
. debugElement
@@ -185,16 +192,17 @@ describe('IntlTelInputComponent', () => {
185
192
expect ( element . getAttribute ( 'data-country-code' ) ) . toBe ( component . options ( ) . onlyCountries ?. [ 0 ] ) ;
186
193
} ) ;
187
194
188
- it ( 'should be possible to set i18n option' , ( ) => {
195
+ it ( 'should be possible to set i18n option' , async ( ) => {
189
196
const localizedCountryName = 'Suisse' ;
190
197
fixture . componentRef . setInput ( 'options' , {
191
198
preferredCountries : [ 'ch' ] ,
192
199
i18n : { ch : localizedCountryName } ,
193
200
onlyCountries : [ 'ch' ]
194
201
} ) ;
195
- component . ngAfterViewInit ( ) ;
196
202
197
- fixture . detectChanges ( ) ;
203
+ await fixture . whenStable ( ) ;
204
+
205
+ component . ngAfterViewInit ( ) ;
198
206
199
207
const element = fixture
200
208
. debugElement
0 commit comments