@@ -21,7 +21,7 @@ describe('static-queries migration with template strategy', () => {
21
21
let warnOutput : string [ ] ;
22
22
23
23
beforeEach ( ( ) => {
24
- runner = new SchematicTestRunner ( 'test' , require . resolve ( '../migrations.json' ) ) ;
24
+ runner = new SchematicTestRunner ( 'test' , require . resolve ( '../test- migrations.json' ) ) ;
25
25
host = new TempScopedNodeJsSyncHost ( ) ;
26
26
tree = new UnitTestTree ( new HostTree ( host ) ) ;
27
27
@@ -97,15 +97,15 @@ describe('static-queries migration with template strategy', () => {
97
97
}
98
98
99
99
async function runMigration ( ) {
100
- await runner . runSchematicAsync ( 'migration-v8- static-queries' , { } , tree ) . toPromise ( ) ;
100
+ await runner . runSchematicAsync ( 'migration-static-queries' , { } , tree ) . toPromise ( ) ;
101
101
}
102
102
103
103
describe ( 'ViewChild' , ( ) => {
104
104
105
105
it ( 'should detect queries selecting elements through template reference' , async ( ) => {
106
106
writeFile ( '/index.ts' , `
107
107
import {Component, NgModule, ViewChild} from '@angular/core';
108
-
108
+
109
109
@Component({template: \`
110
110
<ng-template>
111
111
<button #myButton>My Button</button>
@@ -118,7 +118,7 @@ describe('static-queries migration with template strategy', () => {
118
118
private @ViewChild('myButton') query: any;
119
119
private @ViewChild('myStaticButton') query2: any;
120
120
}
121
-
121
+
122
122
@NgModule({declarations: [MyComp]})
123
123
export class MyModule {}
124
124
` ) ;
@@ -134,7 +134,7 @@ describe('static-queries migration with template strategy', () => {
134
134
it ( 'should detect queries selecting ng-template as static' , async ( ) => {
135
135
writeFile ( '/index.ts' , `
136
136
import {Component, NgModule, ViewChild} from '@angular/core';
137
-
137
+
138
138
@Component({template: \`
139
139
<ng-template #myTmpl>
140
140
My template
@@ -143,7 +143,7 @@ describe('static-queries migration with template strategy', () => {
143
143
export class MyComp {
144
144
private @ViewChild('myTmpl') query: any;
145
145
}
146
-
146
+
147
147
@NgModule({declarations: [MyComp]})
148
148
export class MyModule {}
149
149
` ) ;
@@ -157,29 +157,29 @@ describe('static-queries migration with template strategy', () => {
157
157
it ( 'should detect queries selecting component view providers through string token' , async ( ) => {
158
158
writeFile ( '/index.ts' , `
159
159
import {Component, Directive, NgModule, ViewChild} from '@angular/core';
160
-
160
+
161
161
@Directive({
162
162
selector: '[myDirective]',
163
163
providers: [
164
164
{provide: 'my-token', useValue: 'test'}
165
165
]
166
166
})
167
167
export class MyDirective {}
168
-
168
+
169
169
@Directive({
170
170
selector: '[myDirective2]',
171
171
providers: [
172
172
{provide: 'my-token-2', useValue: 'test'}
173
173
]
174
174
})
175
175
export class MyDirective2 {}
176
-
176
+
177
177
@Component({templateUrl: './my-tmpl.html'})
178
178
export class MyComp {
179
179
private @ViewChild('my-token') query: any;
180
180
private @ViewChild('my-token-2') query2: any;
181
181
}
182
-
182
+
183
183
@NgModule({declarations: [MyComp, MyDirective, MyDirective2]})
184
184
export class MyModule {}
185
185
` ) ;
@@ -202,28 +202,28 @@ describe('static-queries migration with template strategy', () => {
202
202
it ( 'should detect queries selecting component view providers using class token' , async ( ) => {
203
203
writeFile ( '/index.ts' , `
204
204
import {Component, Directive, NgModule, ViewChild} from '@angular/core';
205
-
205
+
206
206
export class MyService {}
207
207
export class MyService2 {}
208
-
208
+
209
209
@Directive({
210
210
selector: '[myDirective]',
211
211
providers: [MyService]
212
212
})
213
213
export class MyDirective {}
214
-
214
+
215
215
@Directive({
216
216
selector: '[myDirective2]',
217
217
providers: [MyService2]
218
218
})
219
219
export class MyDirective2 {}
220
-
220
+
221
221
@Component({templateUrl: './my-tmpl.html'})
222
222
export class MyComp {
223
223
private @ViewChild(MyService) query: any;
224
224
private @ViewChild(MyService2) query2: any;
225
225
}
226
-
226
+
227
227
@NgModule({declarations: [MyComp, MyDirective, MyDirective2]})
228
228
export class MyModule {}
229
229
` ) ;
@@ -247,7 +247,7 @@ describe('static-queries migration with template strategy', () => {
247
247
writeFile ( '/index.ts' , `
248
248
import {Component, NgModule, ViewChild} from '@angular/core';
249
249
import {HomeComponent, HomeComponent2} from './home-comp';
250
-
250
+
251
251
@Component({
252
252
template: \`
253
253
<home-comp></home-comp>
@@ -260,20 +260,20 @@ describe('static-queries migration with template strategy', () => {
260
260
private @ViewChild(HomeComponent) query: any;
261
261
private @ViewChild(HomeComponent2) query2: any;
262
262
}
263
-
263
+
264
264
@NgModule({declarations: [MyComp, HomeComponent, HomeComponent2]})
265
265
export class MyModule {}
266
266
` ) ;
267
267
268
268
writeFile ( `/home-comp.ts` , `
269
269
import {Component} from '@angular/core';
270
-
270
+
271
271
@Component({
272
272
selector: 'home-comp',
273
273
template: '<span>Home</span>'
274
274
})
275
275
export class HomeComponent {}
276
-
276
+
277
277
@Component({
278
278
selector: 'home-comp2',
279
279
template: '<span>Home 2</span>'
@@ -294,12 +294,12 @@ describe('static-queries migration with template strategy', () => {
294
294
writeFile ( '/index.ts' , `
295
295
import {Component, NgModule, ViewChild} from '@angular/core';
296
296
import {MyLibComponent} from 'my-lib';
297
-
297
+
298
298
@Component({templateUrl: './my-tmpl.html'})
299
299
export class MyComp {
300
300
private @ViewChild(MyLibComponent) query: any;
301
301
}
302
-
302
+
303
303
@NgModule({declarations: [MyComp, MyLibComponent]})
304
304
export class MyModule {}
305
305
` ) ;
@@ -319,12 +319,12 @@ describe('static-queries migration with template strategy', () => {
319
319
writeFile ( '/index.ts' , `
320
320
import {Component, NgModule, ViewChild} from '@angular/core';
321
321
import {MyLibComponent} from 'my-lib';
322
-
322
+
323
323
@Component({templateUrl: './my-tmpl.html'})
324
324
export class MyComp {
325
325
private @ViewChild(MyLibComponent) query: any;
326
326
}
327
-
327
+
328
328
@NgModule({declarations: [MyComp, MyLibComponent]})
329
329
export class MyModule {}
330
330
` ) ;
@@ -345,16 +345,16 @@ describe('static-queries migration with template strategy', () => {
345
345
it ( 'should detect queries within structural directive' , async ( ) => {
346
346
writeFile ( '/index.ts' , `
347
347
import {Component, Directive, NgModule, ViewChild} from '@angular/core';
348
-
348
+
349
349
@Directive({selector: '[ngIf]'})
350
350
export class FakeNgIf {}
351
-
351
+
352
352
@Component({templateUrl: 'my-tmpl.html'})
353
353
export class MyComp {
354
354
private @ViewChild('myRef') query: any;
355
355
private @ViewChild('myRef2') query2: any;
356
356
}
357
-
357
+
358
358
@NgModule({declarations: [MyComp, FakeNgIf]})
359
359
export class MyModule {}
360
360
` ) ;
@@ -375,14 +375,14 @@ describe('static-queries migration with template strategy', () => {
375
375
it ( 'should detect inherited queries' , async ( ) => {
376
376
writeFile ( '/index.ts' , `
377
377
import {Component, NgModule, ViewChild} from '@angular/core';
378
-
378
+
379
379
export class BaseClass {
380
380
@ViewChild('myRef') query: any;
381
381
}
382
-
382
+
383
383
@Component({templateUrl: 'my-tmpl.html'})
384
384
export class MyComp extends BaseClass {}
385
-
385
+
386
386
@NgModule({declarations: [MyComp]})
387
387
export class MyModule {}
388
388
` ) ;
@@ -400,7 +400,7 @@ describe('static-queries migration with template strategy', () => {
400
400
it ( 'should add a todo if a query is not declared in any component' , async ( ) => {
401
401
writeFile ( '/index.ts' , `
402
402
import {Component, NgModule, ViewChild, SomeToken} from '@angular/core';
403
-
403
+
404
404
export class NotAComponent {
405
405
@ViewChild('myRef', {read: SomeToken}) query: any;
406
406
}
@@ -420,17 +420,17 @@ describe('static-queries migration with template strategy', () => {
420
420
it ( 'should add a todo if a query is used multiple times with different timing' , async ( ) => {
421
421
writeFile ( '/index.ts' , `
422
422
import {Component, NgModule, ViewChild} from '@angular/core';
423
-
423
+
424
424
export class BaseClass {
425
425
@ViewChild('myRef') query: any;
426
426
}
427
-
427
+
428
428
@Component({template: '<ng-template><p #myRef></p></ng-template>'})
429
429
export class FirstComp extends BaseClass {}
430
-
430
+
431
431
@Component({template: '<span #myRef></span>'})
432
432
export class SecondComp extends BaseClass {}
433
-
433
+
434
434
@NgModule({declarations: [FirstComp, SecondComp]})
435
435
export class MyModule {}
436
436
` ) ;
@@ -448,12 +448,12 @@ describe('static-queries migration with template strategy', () => {
448
448
it ( 'should gracefully exit migration if queries could not be analyzed' , async ( ) => {
449
449
writeFile ( '/index.ts' , `
450
450
import {Component, ViewChild} from '@angular/core';
451
-
451
+
452
452
@Component({template: '<ng-template><p #myRef></p></ng-template>'})
453
453
export class MyComp {
454
454
@ViewChild('myRef') query: any;
455
455
}
456
-
456
+
457
457
// **NOTE**: Analysis will fail as there is no "NgModule" that declares the component.
458
458
` ) ;
459
459
@@ -533,7 +533,7 @@ describe('static-queries migration with template strategy', () => {
533
533
writeFile ( '/src/test.ts' , `
534
534
import {ViewChild} from '@angular/core';
535
535
import {AppComponent} from './app.component';
536
-
536
+
537
537
@Component({template: '<span #test>Test</span>'})
538
538
class MyTestComponent {
539
539
@ViewChild('test') query: any;
@@ -542,7 +542,7 @@ describe('static-queries migration with template strategy', () => {
542
542
543
543
writeFile ( '/src/app.component.ts' , `
544
544
import {Component, ViewChild} from '@angular/core';
545
-
545
+
546
546
@Component({template: '<span #test></span>'})
547
547
export class AppComponent {
548
548
@ViewChild('test') query: any;
@@ -552,7 +552,7 @@ describe('static-queries migration with template strategy', () => {
552
552
writeFile ( '/src/app.module.ts' , `
553
553
import {NgModule} from '@angular/core';
554
554
import {AppComponent} from './app.component';
555
-
555
+
556
556
@NgModule({declarations: [AppComponent]})
557
557
export class MyModule {}
558
558
` ) ;
0 commit comments