Skip to content

Commit 01d95e5

Browse files
cexbrayatmgechev
authored andcommitted
fix(@schematics/angular): implements items type for guard schematics (#15412)
Fixes the type of the items in the `schema.json` for `implements`, as `enum` alone is not picked up by the CLI. Also migrates the existing e2e test to `async/await` and adds another one with `implements` to avoid regressions.
1 parent 6aaf8eb commit 01d95e5

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

packages/schematics/angular/guard/schema.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
"CanActivate",
6060
"CanActivateChild",
6161
"CanLoad"
62-
]
62+
],
63+
"type": "string"
6364
},
6465
"default": [
6566
"CanActivate"
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import {join} from 'path';
22
import {ng} from '../../../utils/process';
3-
import {expectFileToExist} from '../../../utils/fs';
3+
import {expectFileToExist, expectFileToMatch} from '../../../utils/fs';
44

55

6-
export default function() {
6+
export default async function() {
77
// Does not create a sub directory.
88
const guardDir = join('src', 'app');
99

10-
return ng('generate', 'guard', 'test-guard')
11-
.then(() => expectFileToExist(guardDir))
12-
.then(() => expectFileToExist(join(guardDir, 'test-guard.guard.ts')))
13-
.then(() => expectFileToExist(join(guardDir, 'test-guard.guard.spec.ts')));
14-
15-
16-
// Try to run the unit tests.
17-
// TODO: Enable once schematic is updated for rxjs 6
18-
// .then(() => ng('test', '--watch=false'));
10+
await ng('generate', 'guard', 'test-guard');
11+
await expectFileToExist(guardDir);
12+
await expectFileToExist(join(guardDir, 'test-guard.guard.ts'));
13+
await expectFileToMatch(join(guardDir, 'test-guard.guard.ts'), /implements CanActivate/);
14+
await expectFileToExist(join(guardDir, 'test-guard.guard.spec.ts'));
15+
await ng('test', '--watch=false');
1916
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import {join} from 'path';
2+
import {ng} from '../../../utils/process';
3+
import {expectFileToExist,expectFileToMatch} from '../../../utils/fs';
4+
5+
6+
export default async function() {
7+
// Does not create a sub directory.
8+
const guardDir = join('src', 'app');
9+
10+
await ng('generate', 'guard', 'load', '--implements=CanLoad');
11+
await expectFileToExist(guardDir);
12+
await expectFileToExist(join(guardDir, 'load.guard.ts'));
13+
await expectFileToMatch(join(guardDir, 'load.guard.ts'), /implements CanLoad/);
14+
await expectFileToExist(join(guardDir, 'load.guard.spec.ts'));
15+
await ng('test', '--watch=false');
16+
}

0 commit comments

Comments
 (0)