Skip to content

Commit a98c072

Browse files
devversionmmalerba
authored andcommitted
refactor(schematics): add test cases for method-calls and import checks (#13157)
* With the goal of having test cases for each type of source code transformation, this adds test cases for the `method-call checks` and `import-checks`.
1 parent 90ba6fb commit a98c072

File tree

5 files changed

+72
-1
lines changed

5 files changed

+72
-1
lines changed

src/lib/schematics/update/test-cases/misc/constructor-checks.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {runPostScheduledTasks} from '../../../test-setup/post-scheduled-tasks';
33
import {migrationCollection} from '../../../test-setup/test-app';
44
import {createTestAppWithTestCase, resolveBazelDataFile} from '../index.spec';
55

6-
describe('v5 constructor checks', () => {
6+
describe('constructor checks', () => {
77

88
it('should properly report invalid constructor expression signatures', async () => {
99
const inputPath = resolveBazelDataFile(`misc/constructor-checks_input.ts`);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {SchematicTestRunner} from '@angular-devkit/schematics/testing';
2+
import {runPostScheduledTasks} from '../../../test-setup/post-scheduled-tasks';
3+
import {migrationCollection} from '../../../test-setup/test-app';
4+
import {createTestAppWithTestCase, resolveBazelDataFile} from '../index.spec';
5+
6+
describe('v6 import misc checks', () => {
7+
8+
it('should report imports for deleted animation constants', async () => {
9+
const inputPath = resolveBazelDataFile(`misc/import-checks_input.ts`);
10+
const runner = new SchematicTestRunner('schematics', migrationCollection);
11+
12+
runner.runSchematic('migration-01', {}, createTestAppWithTestCase(inputPath));
13+
14+
let output = '';
15+
runner.logger.subscribe(entry => output += entry.message);
16+
17+
await runPostScheduledTasks(runner, 'tslint-fix').toPromise();
18+
19+
expect(output).toMatch(/Found deprecated symbol "SHOW_ANIMATION"/);
20+
expect(output).toMatch(/Found deprecated symbol "HIDE_ANIMATION"/);
21+
});
22+
});
23+
24+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {SHOW_ANIMATION, HIDE_ANIMATION} from '@angular/material';
2+
3+
console.log(SHOW_ANIMATION, HIDE_ANIMATION);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import {SchematicTestRunner} from '@angular-devkit/schematics/testing';
2+
import {runPostScheduledTasks} from '../../../test-setup/post-scheduled-tasks';
3+
import {migrationCollection} from '../../../test-setup/test-app';
4+
import {createTestAppWithTestCase, resolveBazelDataFile} from '../index.spec';
5+
6+
describe('v6 method call checks', () => {
7+
8+
it('should properly report invalid method calls', async () => {
9+
const inputPath = resolveBazelDataFile(`misc/method-call-checks_input.ts`);
10+
const runner = new SchematicTestRunner('schematics', migrationCollection);
11+
12+
runner.runSchematic('migration-01', {}, createTestAppWithTestCase(inputPath));
13+
14+
let output = '';
15+
runner.logger.subscribe(entry => output += entry.message);
16+
17+
await runPostScheduledTasks(runner, 'tslint-fix').toPromise();
18+
19+
expect(output)
20+
.toMatch(/\[15,.*Found call to "FocusMonitor\.monitor".*renderer.*has been removed/);
21+
expect(output)
22+
.toMatch(/\[16,.*Found call to "FocusMonitor\.monitor".*renderer.*has been removed/);
23+
});
24+
});
25+
26+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {AfterViewInit, ElementRef, Renderer2} from '@angular/core';
2+
3+
class FocusMonitor {
4+
monitor(_htmlElement: any, _renderer: Renderer2, _checkChildren: boolean) {}
5+
}
6+
7+
class A implements AfterViewInit {
8+
self = {a: this.focusMonitor};
9+
10+
constructor(private focusMonitor: FocusMonitor,
11+
private elementRef: ElementRef,
12+
private renderer: Renderer2) {}
13+
14+
ngAfterViewInit() {
15+
this.focusMonitor.monitor(this.elementRef.nativeElement, this.renderer, true);
16+
this.self.a.monitor(this.elementRef.nativeElement, this.renderer, true);
17+
}
18+
}

0 commit comments

Comments
 (0)